Create a new list of integers in the range of [start, end]. If a step was given the step between two consecutive list members will be this step. If step was not suppllied, it will be default as 1 "RETURN range(3,8,2)" will yield [3, 5, 7] */
| 327 | If step was not suppllied, it will be default as 1 |
| 328 | "RETURN range(3,8,2)" will yield [3, 5, 7] */ |
| 329 | SIValue AR_RANGE(SIValue *argv, int argc, void *private_data) { |
| 330 | int64_t start = argv[0].longval; |
| 331 | int64_t end = argv[1].longval; |
| 332 | int64_t interval = 1; |
| 333 | if(argc == 3) { |
| 334 | ASSERT(SI_TYPE(argv[2]) == T_INT64); |
| 335 | interval = argv[2].longval; |
| 336 | if(interval == 0) { |
| 337 | ErrorCtx_RaiseRuntimeException("ArgumentError: step argument to range() can't be 0"); |
| 338 | // Incase expection handler wasn't set, return NULL. |
| 339 | return SI_NullVal(); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | uint64_t size = 0; |
| 344 | if((end >= start && interval > 0) || (end <= start && interval < 0)) { |
| 345 | size = 1 + (end - start) / interval; |
| 346 | } |
| 347 | |
| 348 | SIValue array = SI_Array(size); |
| 349 | for(uint64_t i = 0; i < size; i++) { |
| 350 | SIArray_Append(&array, SI_LongVal(start)); |
| 351 | start += interval; |
| 352 | } |
| 353 | return array; |
| 354 | } |
| 355 | |
| 356 | /* Checks if a value is in a given list. |
| 357 | "RETURN 3 IN [1, 2, 3]" will return true */ |
nothing calls this directly
no test coverage detected