From 342a29c7be636707ef56b7c8aee5c41e3002a4b8 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 12 Jul 2024 15:22:46 -0500 Subject: [PATCH] Fix formatting. --- examples/ffi/so.c | 10 +++++----- src/core/corelib.c | 5 +++++ test/suite-corelib.janet | 7 +++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/ffi/so.c b/examples/ffi/so.c index 04cdee80..1ce3120e 100644 --- a/examples/ffi/so.c +++ b/examples/ffi/so.c @@ -211,13 +211,13 @@ int sixints_fn_3(SixInts s, int x) { EXPORTER intint stack_spill_fn(uint8_t a, uint8_t b, uint8_t c, uint8_t d, - uint8_t e, uint8_t f, uint8_t g, uint8_t h, - float i, float j, float k, float l, - float m, float n, float o, float p, - float s1, int8_t s2, uint8_t s3, double s4, uint8_t s5, intint s6) { + uint8_t e, uint8_t f, uint8_t g, uint8_t h, + float i, float j, float k, float l, + float m, float n, float o, float p, + float s1, int8_t s2, uint8_t s3, double s4, uint8_t s5, intint s6) { return (intint) { (a | b | c | d | e | f | g | h) + (i + j + k + l + m + n + o + p), - s1 * s6.a + s2 * s6.b + s3 * s4 * s5 + s1 *s6.a + s2 *s6.b + s3 *s4 *s5 }; } diff --git a/src/core/corelib.c b/src/core/corelib.c index 803403aa..2f09b910 100644 --- a/src/core/corelib.c +++ b/src/core/corelib.c @@ -449,6 +449,11 @@ JANET_CORE_FN(janet_core_range, } count = (count > 0) ? count : 0; int32_t int_count = ceil(count); + if (step > 0.0) { + janet_assert(start + int_count * step >= stop, "bad range code"); + } else { + janet_assert(start + int_count * step <= stop, "bad range code"); + } JanetArray *array = janet_array(int_count); for (int32_t i = 0; i < int_count; i++) { array->data[i] = janet_wrap_number(start + i * step); diff --git a/test/suite-corelib.janet b/test/suite-corelib.janet index e6fe0fea..3c209418 100644 --- a/test/suite-corelib.janet +++ b/test/suite-corelib.janet @@ -69,6 +69,13 @@ (seq [n :range [0 10]] (% n 5 3)) [0 1 2 0 1 0 1 2 0 1]) "variadic mod") +# linspace range +(assert (deep= @[0 1 2 3] (range 4)) "range 1") +(assert (deep= @[0 1 2 3] (range 3.01)) "range 2") +(assert (deep= @[0 1 2 3] (range 3.999)) "range 3") +(assert (deep= @[0.8 1.8 2.8 3.8] (range 0.8 3.999)) "range 4") +(assert (deep= @[0.8 1.8 2.8 3.8] (range 0.8 3.999)) "range 5") + (assert (< 1.0 nil false true (fiber/new (fn [] 1)) "hi" -- 2.45.2