diff --git a/PRECISION.md b/PRECISION.md index 1ade173..88e2ac9 100644 --- a/PRECISION.md +++ b/PRECISION.md @@ -212,7 +212,8 @@ Ceil is the ceiling function $x \mapsto \lceil x \rceil$, returning the integer It returns an empty interval on an empty argument. -It outputs integers, so it doesn't need to represent bits after the binary point: $l'=0$. +Although its result is mathematically an integer, the implementation of the primitive uses `std::ceil`, whose return value is a floating-point number. +We thus chose to set the output precision to $-1$, which might be under-optimal, but will force the interval library and the code generator to treat the result as floating-point. ## Checkbox @@ -229,6 +230,15 @@ The smallest gap between two consecutive images is attained at one of the multip While it is possible to bound how close to a multiple of $\pi$ a fixed-point number will be, it is too costly to compute for this application, and we will consider that the difference computed at the smallest multiple of $\pi$ (i.e. 0) gives sufficient precision. +## Floor + +Floor is the floor function $x \mapsto \lfloor x \rfloor$, returning the integer right above its argument. + +It returns an empty interval on an empty argument. + +Although its result is mathematically an integer, the implementation of the primitive uses `std::floor`, whose return value is a floating-point number. +We thus chose to set the output precision to $-1$, which might be under-optimal, but will force the interval library and the code generator to treat the result as floating-point. + # Typology of functions ## Binary operator diff --git a/interval/intervalCeil.cpp b/interval/intervalCeil.cpp index 519f111..aeaf20f 100644 --- a/interval/intervalCeil.cpp +++ b/interval/intervalCeil.cpp @@ -31,7 +31,9 @@ interval interval_algebra::Ceil(const interval& x) if (x.isEmpty()) { return x; } - return {ceil(x.lo()), ceil(x.hi()), 0}; // ceil yields integers, thus with LSB 0 + return {ceil(x.lo()), ceil(x.hi()), -1 }; // even though the output of floor are mathematical integers, + // they are implemented as floats and thus should not be given precision 0, + // lest it be cast as an int } void interval_algebra::testCeil() diff --git a/interval/intervalFloor.cpp b/interval/intervalFloor.cpp index 75c59b4..4681c14 100644 --- a/interval/intervalFloor.cpp +++ b/interval/intervalFloor.cpp @@ -29,9 +29,11 @@ namespace itv { interval interval_algebra::Floor(const interval& x) { if (x.isEmpty()) { - return {}; + return x; } - return {floor(x.lo()), floor(x.hi()), 0}; // floor yields integers, thus with LSB 0 + return {floor(x.lo()), floor(x.hi()), -1}; // even though the output of floor are mathematical integers, + // they are implemented as floats and thus should not be given precision 0, + // lest it be cast as an int } void interval_algebra::testFloor()