[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GUB and mpfr/mpc
From: |
Dan Eble |
Subject: |
Re: GUB and mpfr/mpc |
Date: |
Thu, 4 Dec 2014 22:38:35 -0500 |
On Dec 4, 2014, at 09:58 , Masamichi HOSODA <address@hidden> wrote:
>
>> Also, the mention of optimization reminds me of one of the horrors of
>> floating point types: a value in a register can quietly be changed when it
>> is written to memory. Take a look at some of the “myths” in section 1 of
>> https://hal.archives-ouvertes.fr/hal-00128124/en/ .
[…]
> I think that floating point can be used as long as it's used correct.
>
> operator== shouldn't be used for comparison of floating point values.
> operator!= shouldn't be used too.
> operator< and operator> may be used.
The issue is more complex than that. Sit down and try this:
#include <iostream>
int main(void)
{
double a = 0;
double b = 0;
std::cin >> a;
std::cin >> b;
double x = a/b;
if (x < a/b) {
std::cout << "x:" << x << " < " << (a/b) << std::endl;
}
volatile double y = x;
if (y < a/b) {
std::cout << "y:" << y << " < " << (a/b) << std::endl;
}
return 0;
}
Results in LilyDev 3:
$ g++ fp.cc -o fp && (echo "2 3" | ./fp)
x:0.666667 < 0.666667
y:0.666667 < 0.666667
$ g++ -O3 fp.cc -o fp && (echo "2 3" | ./fp)
y:0.666667 < 0.666667
Add looping and you’ve got fatal issues. (And if you’re like me, steam will
erupt from your ears any second now...)
—
Dan
- Re: GUB and mpfr/mpc, (continued)
- Re: GUB and mpfr/mpc, David Kastrup, 2014/12/01
- Re: GUB and mpfr/mpc, Trevor Daniels, 2014/12/01
- Re: GUB and mpfr/mpc, Masamichi HOSODA, 2014/12/02
- Re: GUB and mpfr/mpc, David Kastrup, 2014/12/02
- Re: GUB and mpfr/mpc, Masamichi HOSODA, 2014/12/03
- Re: GUB and mpfr/mpc, Dan Eble, 2014/12/04
- Re: GUB and mpfr/mpc, Dan Eble, 2014/12/04
- Re: GUB and mpfr/mpc, Masamichi HOSODA, 2014/12/04
- Re: GUB and mpfr/mpc, Masamichi HOSODA, 2014/12/04
- Re: GUB and mpfr/mpc,
Dan Eble <=
- Re: GUB and mpfr/mpc, Masamichi HOSODA, 2014/12/05
- Re: GUB and mpfr/mpc, David Kastrup, 2014/12/05
- Re: GUB and mpfr/mpc, Dan Eble, 2014/12/05
- Re: GUB and mpfr/mpc, David Kastrup, 2014/12/06
- Re: GUB and mpfr/mpc, Dan Eble, 2014/12/06
- Re: GUB and mpfr/mpc, Masamichi HOSODA, 2014/12/08
- Re: GUB and mpfr/mpc, David Kastrup, 2014/12/08
- Re: GUB and mpfr/mpc, Dan Eble, 2014/12/08
- Re: GUB and mpfr/mpc, Keith OHara, 2014/12/21
Re: GUB and mpfr/mpc, Masamichi Hosoda, 2014/12/28