Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
- Subject: Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
- From: Asiga Nael <email@hidden>
- Date: Fri, 03 Jan 2014 23:29:48 +0000 (GMT)
On 3 Jan 2014, at 2:50 PM, Fritz
Anderson <email@hidden>
wrote:
> if (valueOrZero != 0.0) ratio = fNumerator / valueOrZero;
Just to add some light to this use I was doing of floating point equality comparisons for avoiding division by zero, I searched the web and found that -contrary to my belief- this test is "unsafe" too: while it's true that if a fp number isn't exactly zero it won't produce a division by zero, however, it can still generate infinity if it's a denormal (or subnormal according to current IEEE naming). So, the really safe way is to use the isnormal() macro before doing the division: this will guarantee there's no division by zero and there's no infinity result, if I've read correctly some web pages.
asiga
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden