Boost logo

Boost :

From: Greg Chicares (chicares_at_[hidden])
Date: 2001-05-21 20:18:14


Beman Dawes wrote:
>
> At 01:34 PM 5/21/2001, Jens Maurer wrote:
>
> >Aren't there any "strict IEEE" flags on Windows? Nearly every
> >Unix compiler appears to have these.
>
> I couldn't find such a flag for Metrowerks - maybe Howard has some insight.
>
> Borland has an -ff- flag, but limits_test.cpp still fails with it set.
>
> Microsoft has a /Op[-] flag, but limits_test.cpp still fails with it set
> either way.
>
> Sorry, I know that isn't much help.

It's all the help there is, at least for borland, which has no "strict
IEEE" flag. The closest thing is the '-ff-' flag, which means "do not
ignore type conversions" as in the following program:

#include <iostream>

int main()
{
  std::cout.setf(std::iostream::fixed);
  std::cout.precision(20);

  double x = 2.718281828459045 / 2.0;
  x = (float)(2*x);
  std::cout << x << '\n';
}

std::numeric_limits<float>::digist10 is six on my hardware...

gcc always gives
  2.71828174591064453125 // six-digit accuracy
whether or not we use these options:
  g++ -ffast-math -ffloat-store

borland gives
  2.71828182845904509100 // sixteen-digit accuracy
in its "ANSI" (!= "IEEE") mode, and the desired
  2.71828174591064453100 // six-digit accuracy
only if we use
  bcc32 -ff-

I didn't test with optimization, because optimization should not be
required for correctness.

There's nothing else to be done with command-line options: there's no
borland option to set the floating-point hardware to allow quiet NaNs
to work without raising an exception.

Here are details for anyone who's really interested:

***LOGS***

C:\testing>bcc32 -ff- fastmath.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
fastmath.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

C:\testing>fastmath
2.71828174591064453100

C:\testing>bcc32 -ff fastmath.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
fastmath.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

C:\testing>fastmath
2.71828182845904509100

C:\testing>bcc32 -A fastmath.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
fastmath.cpp:
Warning W8020 c:\Borland\Bcc55\include\istream.h 445: 'std::operator == <T,charT
,traits,Distance>(const istream_iterator<T,charT,traits,Distance> &,const istrea
m_iterator<T,charT,traits,Distance> &)' is declared as both external and static
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

C:\testing>fastmath
2.71828182845904509100

C:\testing>g++ -Wall -ansi -pedantic fastmath.cpp

C:\testing>a
2.71828174591064453125

C:\testing>g++ -Wall -ansi -pedantic fastmath.cpp -ffast-math

C:\testing>a
2.71828174591064453125

C:\testing>g++ -Wall -ansi -pedantic fastmath.cpp -ffast-math -ffloat-store

C:\testing>a
2.71828174591064453125

C:\testing>g++ -Wall -ansi -pedantic fastmath.cpp -fno-fast-math -fno-float-store

C:\testing>a
2.71828174591064453125

C:\testing>g++ -v
Reading specs from
  C:\GCC-29~1.2-1\BIN\..\lib\gcc-lib\i386-mingw32msvc\2.95.2\specs
gcc version 2.95.2 19991024 (release)

***COMPILERS' DOCUMENTATION OF RELEVANT OPTIONS***

gcc options:

-ffast-math
     This option allows GCC to violate some ANSI or IEEE rules and/or
     specifications in the interest of optimizing code for speed. For
     example, it allows the compiler to assume arguments to the sqrt
     function are non-negative numbers and that no floating-point
     values are NaNs.
-ffloat-store
     Do not store floating point variables in registers, and inhibit
     other options that might change whether a floating point value
     is taken from a register or memory. This option prevents
     undesirable excess precision on machines such as the 68000 where
     the floating registers (of the 68881) keep more precision than a
     double is supposed to have. Similarly for the x86 architecture.
     For most programs, the excess precision does only good, but a few
     programs rely on the precise definition of IEEE floating point.
     Use `-ffloat-store' for such programs, after modifying them to
     store all pertinent intermediate computations into variables.

borland options:

ANSI (Command-line equivalent: -A)
The ANSI option compiles C and C++ ANSI-compatible code, allowing for
maximum portability. Non-ANSI keywords are ignored as keywords.

Fast floating point (Command-line equivalent: -ff)
When Fast Floating Point is on, floating-point operations are
optimized without regard to explicit or implicit type conversions.
Calculations can be faster than under ANSI operating mode.
When this option is unchecked (-ff-), the compiler follows strict ANSI
rules regarding floating-point conversions.
Default = OFF [my note: the default is actually non-IEEE754 '-ff']

Borland C++ has a fast floating-point option (the -ff command-line
compiler option). It can be turned off with -ff- on the command line.
Its purpose is to allow certain optimizations that are technically
contrary to correct C semantics. For example,

double x;

x = (float)(3.5*x);

To execute this correctly, x is multiplied by 3.5 to give a double
that is truncated to float precision, then stored as a double in x.
Under the fast floating-point option, the long double product is
converted directly to a double. Since very few programs depend on the
loss of precision in passing to a narrower floating-point type, fast
floating point is the default.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk