From -7164449852717695883
X-Google-Thread: f78e5,eb811809d4f61b12
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!pd7cy1no!shaw.ca!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: wade@stoner.com
Newsgroups: comp.std.c++
Subject: Re: Using extended precision in floating point
Date: Wed, 17 May 2006 15:45:44 CST
Organization: http://groups.google.com
Lines: 63
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <1147894914.582706.183340@g10g2000cwb.googlegroups.com>
References: <1147882581.972497.100340@u72g2000cwu.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1147894920 28035 127.0.0.1 (17 May 2006 19:42:00 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 17 May 2006 19:42:00 +0000 (UTC)
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@ucar.edu
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1),gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: g10g2000cwb.googlegroups.com; posting-host=65.16.217.10;
   posting-account=1rcVOQwAAACiq302N7tDjZ9huexzBBxn
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
Xref: g2news2.google.com comp.std.c++:2030

kanze wrote:
> As a result of a recent discussion in the French language
> newsgroup, I am now unsure as to when the compiler can use
> extra precision in floating point operations.

I think it is a QOI issue.  The standard doesn't say.  Or perhaps, 5/5
is saying that for the typical floating point representation (where
one-third is not representable), 1.0/3.0 is UB.

In "The Standard C Library", PJP says "... the C Standard is mostly
descriptive in the area of floating-point arithmetic.  It endeavors to
define enough terms to talk about the parameters of floating point.
But it says little that is prescriptive about getting the right
answer."  I don't believe C++ does significantly better.

Regardless of what the standard says, the current best you'll find is a
vendor that tells you the facts abot what his compiler does.

I'm not an expert in this stuff.  I read the documentation, and then
try to find a set of compiler options that make paranoia.c (from
netlib) happy when other optimizations are turned on.

MS documents some floating point modes called, "fast", "precise", and
"strict."  My reading is that

- fast: Compiler is free to assume that fp-math obeys the rules of
real-math.  Extra precision may be carried over between statements (or
statements may be rewritten, if real math would mean the old statements
and new statements give the same result).

- precise: Compiler may perform optimizations that give the correct
result assuming that you leave the fp processor in its default state
(default rounding mode, division by zero produces a non-signaling NAN,
etc.).  Extended precision is "tossed" at assignments, casts, and
function calls.  The compiler may use low-level contraction (a*b+c)
instructions, even when that instruction can give a "better" answer
than multiply followed by add.

-strict: No contractions.  Extended precision is "tossed" at
assignments, casts, and function calls.  Compiler does not assume that
you are leaving the floating point mode alone, so
   float x = 1.0 / 3.0;
   Bar();
   float y = 1.0 / 3.0;
the compiler does not assume x==y (since Bar() might have changed the
rounding mode), and 1.0 / 3.0 is not a compile-time constant, for the
same reason.

As far as I can tell from the MS documentation, paranoia.c should be
happy with "precise."  However, with VC8, paranoia.c (double precision)
isn't happy until "strict."  I don't know if this is a VC bug (can't
find it in their knowledge base, and when I try a bug report, MS
passport stuff gets in the way) or if I am misreading the
documentation.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/floapoint.asp

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



