Always false float comparisons

Johannes Pfau via Digitalmars-d digitalmars-d at puremagic.com
Wed May 18 04:40:54 PDT 2016


Am Wed, 18 May 2016 04:11:08 -0700
schrieb Walter Bright <newshound2 at digitalmars.com>:

> On 5/18/2016 3:15 AM, deadalnix wrote:
> > On Wednesday, 18 May 2016 at 08:21:18 UTC, Walter Bright wrote:  
> >> Trying to make D behave exactly like various C++ compilers do,
> >> with all their semi-documented behavior and semi-documented
> >> switches that affect constant folding behavior, is a hopeless task.
> >>
> >> I doubt various C++ compilers are this compatible, even if they
> >> follow the same ABI.
> >>  
> >
> > They aren't. For instance, GCC use arbitrary precision FB, and LLVM
> > uses 128 bits soft floats in their innards.  
> 
> Looks like LLVM had the same idea as myself.
> 
> Anyhow, this pretty much destroys the idea that I have proposed some
> sort of cowboy FP that's going to wreck FP programs.
> 
> (What is arbitrary precision FB?)

A claim from GMP, a library used by GCC:

> GMP is a free library for arbitrary precision arithmetic, operating on
> signed integers, rational numbers, and floating-point numbers. There
> is
> no practical limit to the precision except the ones implied by the
> available memory in the machine GMP runs on.

It's difficult to find reliable information, but I think GCC always uses
the target precision for constant folding:
https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gccint/Floating-Point.html#Floating-Point

> Because different representation systems may offer different amounts
> of
> range and precision, all floating point constants must be represented
> in the target machine's format. Therefore, the cross compiler cannot
> safely use the host machine's floating point arithmetic; it must
> emulate the target's arithmetic. To ensure consistency, GCC always
> uses
> emulation to work with floating point values, even when the host and
> target floating point formats are identical. 


More information about the Digitalmars-d mailing list