Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > isnan or isntnan?

Thread Tools

isnan or isntnan?

Tim Rentsch
Posts: n/a
jacob navia <(E-Mail Removed)> writes:

> Le 16/11/10 20:04, Nick Bowler a @C3{A9}crit :
>> On Sat, 13 Nov 2010 16:48:42 +0000, JohnF wrote:
>>> It seems that isnan(y2) must be false since it prints 0 for the nanerror
>>> variable, but then it prints nan for y2 anyway. What could be going on,
>>> and how do I proceed to debug it? Thanks,

>> Since I didn't see it posted elsewhere in this thread, it should be
>> noted that GCC's -ffast-math option implies -ffinite-math-only, which
>> tells the compiler that it may assume all floating point values are
>> finite. This means that GCC can and will replace all calls to isnan or
>> isinf with a constant 0.

> !!!!!!!!!!!!!!!!!!!!!!!!
> This is one of the worst bugs of gcc I have ever seen.
> [snip elaboration]

Why does it bother you so much that gcc has an option
supporting a non-conforming extension? Doesn't lccwin
have options that support non-conforming extensions?
Reply With Quote
Posts: n/a
On Mon, 22 Nov 2010 09:56:02 +0100, jacob navia wrote:

> Finite math can be assumed. Optimizing away a call to isnan is another
> thing.

No. It. Isn't.

For a start, the standard explicitly states that isnan() is a macro. Once
the preprocessor has done its business, the compiler may not even
know that there *was* a call to isnan().

Beyond that, once a compiler starts optimising, there's a good chance that
the expression which was being passed to isnan() doesn't actually exist in
any shape or form.

Have you ever tried debugging optimised code? If you do, you'll find that
lots of variables no longer exist, entire statements no longer exist.
Because the compiler basically treats the original code as a specification
and then generates entirely different code whose only resemblance to the
original is that it produces the same result.

If the compiler was obliged to call the same functions in the same
sequence, there wouldn't be much point in enabling optimisation in the
first place.

Reply With Quote
Keith Thompson
Posts: n/a
jacob navia <(E-Mail Removed)> writes:
> Le 16/11/10 22:36, Keith Thompson a écrit :
> You are confusing
> The option given by the user was
> -ffast-math
> and THAT option turns on IMPLICITELY finite-math
> But obviously, you are right.
> When I buy a coffee machine "guaranted 3 months",
> I can't fix it in the store because in a very small paragraph
> of the thick contract (that was less than gcc's doc about options)
> was written in small print that "I have to pay the transport to
> the workshop"... that costs more than the machine
> Clever isn't it?

Here's a better analogy.

You buy a coffee machine. When used in the normal manner, it makes
good coffee and works in a reasonably intuitive way.

Somewhere in the coffee machine's manual, there's a paragraph that
says that, if you really want to, you can remove three screws on the
base, open up a panel, and flip a switch to change the setting on
the heater. By doing so, you can make your coffee 10% faster, but
you risk starting a fire if you don't have just the required ratio
of coffee beans and water. (If you don't flip the switch, a safety
feature turns off the heater before that can happen, but it can't
act quickly enough at the higher setting.) And the ratio is such
that you can't make really strong coffee with the switch flipped.

Flipping the switch gives you better speed at the expense of reduced
functionality and greater risk of malfunction. It's just the thing
for those coffee brewing speed competitions all the kids are into
these days.

There is no reasonable way you'd even know about the switch if you
didn't read the manual, you couldn't flip it accidentally if you
didn't know about it, and if you did read the manual you'd know about
the risks. You'd also know that the bean/water ratio requirement
means you can't make really strong coffee if the switch is enabled,
and you happen to like your coffee really string. (No cream, no sugar,
just a sprinkling of NaNs.)

What you seem to be doing is buying this coffee maker with the
intention of making really strong coffee, and complaining that
it's defective because it doesn't work the way you want it to if
you flip the switch.

Except that you didn't actually buy the coffee maker (even though
it's free); you're just complaining about it because somebody else
(who had no problem with it) described the switch's behavior.
(I won't assume that this has anything to do with the fact that
you manufacture a competitive coffee maker.)

What exactly was your problem again?

Keith Thompson (The_Other_Keith) Removed) <>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Reply With Quote
Tom St Denis
Posts: n/a
On Nov 22, 3:56*am, jacob navia <(E-Mail Removed)> wrote:
> Le 22/11/10 00:22, Seebs a crit :
> >> I could conceive that making those assumptions about data manipulated by
> >> the compiler could be (maybe) OK. But just "pessimizing" away a call
> >> to a function?

> > Uh, yeah. *Happens all the time. *Do you honestly think that most compilers
> > generate a function call for strlen("foo")?

> So WHAT?
> strlen("foo") can give only ONE result. isnan() surely NOT, unless
> you apply bad specs to the limit of nonsense.
> Finite math can be assumed. Optimizing away a call to isnan is another
> thing.

Why not just not pass -ffast-math if you don't want this behaviour?

-ffast-math is an OPTIMIZATION not a requisite to compile code.

Reply With Quote
Posts: n/a
Tom St Denis wrote:

> Why not just not pass -ffast-math if you don't want this behaviour?
> -ffast-math is an OPTIMIZATION not a requisite to compile code.

You see, the problem is, if he were to do that, he'd have to give up
a perfectly "good" excuse to diss GCC.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
isnan() for complex data jacob navia C++ 5 02-05-2008 02:09 AM
isinf() & isnan() Priya C++ 2 09-19-2006 12:19 PM
isNaN function jscript =?Utf-8?B?c2lhag==?= ASP .Net 4 03-08-2005 05:59 PM
UNIX's int isnan(double x) routine for Windows/Visual C/C++ 6.0 ? Skybuck Flying C Programming 5 07-17-2004 08:00 AM
Re: help on rewritting c++ for Mac into MSDOS - "IsNan.c" 5832 Bytes Christopher Benson-Manica C++ 0 05-11-2004 01:19 PM