Skip to content

Commit

Permalink
Force precision of float casts to be <0
Browse files Browse the repository at this point in the history
  • Loading branch information
Agathe Herrou committed Mar 13, 2024
1 parent 72421ee commit bc580e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
7 changes: 2 additions & 5 deletions PRECISION.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,8 @@ If $\delta$ is computed to be $0$, we replace it by the Taylor approximation of

FloatCast is the operator casting values into floats.

The same precision is needed for the output as for the input.

**Question:** what happens if we cast an `int` value in `float` using that rule?
The precision will remain above $0$ and the output value will be interpreted as `int` because of that, defeating the purpose of a `float` cast.
It would maybe be better to reassign precisions greater than $0$ to $-1$ in order to force the `float` typing.
If we cast an `int` value in `float` without modifying the precision, it will remain above $0$ and the output value will be interpreted as `int` because of that, defeating the purpose of a `float` cast.
Having observed that, we reassign precisions greater than $0$ to $-1$ in order to force the `float` typing.

## FloatNum

Expand Down
8 changes: 3 additions & 5 deletions interval/intervalFloatCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ namespace itv {

interval interval_algebra::FloatCast(const interval& x)
{
return x;
// return x;

// alternatively, to force the float typing
/*
return {x.lo(), x.hi(), std::min(x.lsb(), -1)};
*/
// LSB with -1 value to force the float typing
return {x.lo(), x.hi(), std::min(x.lsb(), -1)};
}

void interval_algebra::testFloatCast()
Expand Down

0 comments on commit bc580e9

Please sign in to comment.