Displaying 5 results from an estimated 5 matches for "fe_upward".
2017 Nov 04
2
FW: clarification needed for the constrained fp implementation.
...ke this:
>
> #include <fenv.h>
>
> double someFunc(double A, double B, bool ForceRoundUp) {
>
> #pragma STDC FENV_ACCESS ON
>
> double Result;
>
> if (ForceRoundUp) {
>
> int OldRM = fegetround();
>
> fesetround(FE_UPWARD);
>
> Result = A/B;
>
> fesetround(OldRM);
>
> } else {
>
> Result = A/B;
>
> }
>
> return Result;
>
> }
>
>
> ...
> abridge
> ...
>
>
> What I’m thinking is that we need somethin...
2017 Nov 03
2
FW: clarification needed for the constrained fp implementation.
...these if you have set FENV_ACCESS to the "on" state. A typical usage might look like this:
#include <fenv.h>
double someFunc(double A, double B, bool ForceRoundUp) {
#pragma STDC FENV_ACCESS ON
double Result;
if (ForceRoundUp) {
int OldRM = fegetround();
fesetround(FE_UPWARD);
Result = A/B;
fesetround(OldRM);
} else {
Result = A/B;
}
return Result;
}
So you see here that there are explicit calls to change the rounding mode. If you were to do this in clang today, the generated IR would look like this:
define double @someFunc(double, double, i1) {...
2016 Aug 18
5
fenv.h vs the optimizer
...point operations?
When run on my macbook, the example code on
http://en.cppreference.com/w/c/numeric/fenv/FE_exceptions does not print
all the expected exceptions.
Other examples:
void foo() {
fesetround(FE_DOWNWARD);
printf("foo downward: %f\n", rint(0.5));
fesetround(FE_UPWARD);
printf("foo upward: %f\n", rint(0.5));
}
If compiled with optimization, only one call to rint() is made and the
result is reused.
void bar(double a, double b) {
feclearexcept(FE_INEXACT);
a / b;
printf("bar %f / %f is %sexact\n", a, b, fetestexcept(FE_IN...
2014 Mar 26
3
[LLVMdev] [cfe-dev] computing a conservatively rounded square of a double
On 03/26/2014 11:36 AM, Geoffrey Irving wrote:
> I am trying to compute conservative lower and upper bounds for the
> square of a double. I have set the rounding mode to FE_UPWARDS
> elsewhere, so the code is
>
> struct Interval {
> double nlo, hi;
> };
>
> Interval inspect_singleton_sqr(const double x) {
> Interval s;
> s.nlo = x * -x;
> s.hi = x * x;
> return s;
> }
>
> Both multiplies are necessary, since they round...
2015 Aug 21
2
The semantics of the fptrunc instruction with an example of incorrect optimisation
...target I'm using (x86_64) that **is not** what happens.
Consider the following example in C
```
#include <stdio.h>
#include <fenv.h>
int main() {
double x = 0.3;
fesetround(FE_TONEAREST);
float y = (float) x;
printf("y (nearest):%a\n", y);
fesetround(FE_UPWARD);
y = (float) x;
printf("y (upward):%a\n", y);
fesetround(FE_DOWNWARD);
y = (float) x;
printf("y (downward):%a\n", y);
return (int) y;
}
```
If I get the unoptimised LLVM IR for this by running ``clang -O0
float.c -emit-llvm -c -o float.clang.o0.bc`` I c...