The GNU Autoconf manual provides a work-around for missing isinf()
and isnan() functions, which exist in C99 and many, but not all,
pre-C99 implementations:
http://www.gnu.org/software/libtool/manual/autoconf/Function-Portability.html
The given definition of isinf(x) boils down to return isnan (x - x),
which will return true for NaNs. Surely this is wrong?
-- Richard
--
Please remember to mention me / in tapes you leave behind.
|
|
0
|
|
|
|
Reply
|
richard91 (3683)
|
10/8/2008 2:11:29 PM |
|
Richard Tobin wrote:
> The GNU Autoconf manual provides a work-around for missing isinf()
> and isnan() functions, which exist in C99 and many, but not all,
> pre-C99 implementations:
>
> http://www.gnu.org/software/libtool/manual/autoconf/Function-Portability.html
>
> The given definition of isinf(x) boils down to return isnan (x - x),
> which will return true for NaNs. Surely this is wrong?
It seems so to me.
|
|
0
|
|
|
|
Reply
|
jameskuyper (5207)
|
10/8/2008 2:24:05 PM
|
|
"Richard Tobin" <richard@cogsci.ed.ac.uk> wrote in message
int isinf(double x)
{
if(x > DBL_MAX)
return 1;
else
return 0;
}
|
|
0
|
|
|
|
Reply
|
regniztar (3128)
|
10/8/2008 6:39:54 PM
|
|
"Malcolm McLean" <regniztar@btinternet.com> writes:
> "Richard Tobin" <richard@cogsci.ed.ac.uk> wrote in message
>
> int isinf(double x)
> {
> if(x > DBL_MAX)
> return 1;
> else
> return 0;
> }
That fails for negative infinity.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|
|
0
|
|
|
|
Reply
|
kst-u (21545)
|
10/8/2008 6:59:34 PM
|
|
Richard Tobin wrote:
>
> The GNU Autoconf manual provides a work-around for missing isinf()
> and isnan() functions, which exist in C99 and many, but not all,
> pre-C99 implementations:
>
> http://www.gnu.org/software/libtool/manual/autoconf/Function-Portability.html
>
> The given definition of isinf(x) boils down to return isnan (x - x),
> which will return true for NaNs. Surely this is wrong?
Think about it. If x is not a number, what can you say about x-x?
I fail to see any way that expression could become a number.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
|
|
0
|
|
|
|
Reply
|
cbfalconer (19183)
|
10/9/2008 12:35:17 AM
|
|
On 8 Oct 2008 14:11:29 GMT,
Richard Tobin <richard@cogsci.ed.ac.uk> wrote:
> The GNU Autoconf manual provides a work-around for missing isinf()
> and isnan() functions, which exist in C99 and many, but not all,
> pre-C99 implementations:
>
> http://www.gnu.org/software/libtool/manual/autoconf/Function-Portability.html
>
> The given definition of isinf(x) boils down to return isnan (x - x),
> which will return true for NaNs. Surely this is wrong?
If isnan(x) is true, then x - x is also NaN, and isnan(x - x) would also
be true.
Check Annex F to the C99 standard. Specifically, in F8.2 it is made
clear that the equivalence x - x == 0.0 does not hold when x can be NaN
or Inf.
Martien
--
|
Martien Verbruggen | I took an IQ test and the results were
| negative.
|
|
|
0
|
|
|
|
Reply
|
mgjv (156)
|
10/9/2008 3:37:28 AM
|
|
CBFalconer <cbfalconer@yahoo.com> writes:
> Richard Tobin wrote:
>>
>> The GNU Autoconf manual provides a work-around for missing isinf()
>> and isnan() functions, which exist in C99 and many, but not all,
>> pre-C99 implementations:
>>
>> http://www.gnu.org/software/libtool/manual/autoconf/Function-Portability.html
>>
>> The given definition of isinf(x) boils down to return isnan (x - x),
>> which will return true for NaNs. Surely this is wrong?
>
> Think about it. If x is not a number, what can you say about x-x?
> I fail to see any way that expression could become a number.
Indeed, if x is NaN then so is x-x, so isnan(x-x) would be true. But
7.12.3.3 says "The isinf macro returns a nonzero value if and only if
its argument has an infinite value." That makes it sound as if
isinf(x) should return zero if x is NaN, since NaN does not have an
infinite value.
|
|
0
|
|
|
|
Reply
|
nate14 (514)
|
10/9/2008 4:04:49 AM
|
|
In article <o9ujcg.aa1.ln@news.heliotrope.home>,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>> The given definition of isinf(x) boils down to return isnan (x - x),
>> which will return true for NaNs. Surely this is wrong?
>If isnan(x) is true, then x - x is also NaN, and isnan(x - x) would also
>be true.
Exactly. And that would be wrong, because isinf(x) should be false
if x is a NaN.
Anyway, I eventually discovered that this mistake has already been
reported to the autoconf project.
-- Richard
--
Please remember to mention me / in tapes you leave behind.
|
|
0
|
|
|
|
Reply
|
richard91 (3683)
|
10/9/2008 10:57:07 AM
|
|
Martien Verbruggen wrote:
> On 8 Oct 2008 14:11:29 GMT,
> Richard Tobin <richard@cogsci.ed.ac.uk> wrote:
>> The GNU Autoconf manual provides a work-around for missing isinf()
>> and isnan() functions, which exist in C99 and many, but not all,
>> pre-C99 implementations:
>>
>> http://www.gnu.org/software/libtool/manual/autoconf/Function-Portability.html
>>
>> The given definition of isinf(x) boils down to return isnan (x - x),
>> which will return true for NaNs. Surely this is wrong?
>
> If isnan(x) is true, then x - x is also NaN, and isnan(x - x) would also
> be true.
>
> Check Annex F to the C99 standard. Specifically, in F8.2 it is made
> clear that the equivalence x - x == 0.0 does not hold when x can be NaN
> or Inf.
Exactly. Which is why isnan(x-x) doesn't make sense as an implementation
of ifinf(x). isinf(x) isn't supposed to return true when x is a NaN;
it's only supposed to return true when x is infinite.
|
|
0
|
|
|
|
Reply
|
jameskuyper (5207)
|
10/9/2008 12:57:20 PM
|
|
On Thu, 09 Oct 2008 12:57:20 GMT,
James Kuyper <jameskuyper@verizon.net> wrote:
> Martien Verbruggen wrote:
>> On 8 Oct 2008 14:11:29 GMT,
>> Richard Tobin <richard@cogsci.ed.ac.uk> wrote:
>>> The GNU Autoconf manual provides a work-around for missing isinf()
>>> and isnan() functions, which exist in C99 and many, but not all,
>>> pre-C99 implementations:
>>>
>>> http://www.gnu.org/software/libtool/manual/autoconf/Function-Portability.html
>>>
>>> The given definition of isinf(x) boils down to return isnan (x - x),
>>> which will return true for NaNs. Surely this is wrong?
>>
>> If isnan(x) is true, then x - x is also NaN, and isnan(x - x) would also
>> be true.
>>
>> Check Annex F to the C99 standard. Specifically, in F8.2 it is made
>> clear that the equivalence x - x == 0.0 does not hold when x can be NaN
>> or Inf.
>
> Exactly. Which is why isnan(x-x) doesn't make sense as an implementation
> of ifinf(x). isinf(x) isn't supposed to return true when x is a NaN;
> it's only supposed to return true when x is infinite.
Sorry all. I misread the isinf() as isnan(). I thought the OP was
confused about why isnan(x-x) returned true.
Martien
--
| Yes; Windows is great for running &
Martien Verbruggen | developing viruses, for instance. It's also
| very popular, but then again, so is the
| common cold. -- Dave Hinz
|
|
0
|
|
|
|
Reply
|
mgjv (156)
|
10/9/2008 10:40:16 PM
|
|
|
9 Replies
52 Views
(page loaded in 0.144 seconds)
|