Skip to content

Commit

Permalink
Floor and ceil
Browse files Browse the repository at this point in the history
  • Loading branch information
Agathe Herrou committed Mar 12, 2024
1 parent 9a7690e commit dc45b16
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
12 changes: 11 additions & 1 deletion PRECISION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion interval/intervalCeil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions interval/intervalFloor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit dc45b16

Please sign in to comment.