473,883 Members | 1,617 Online

# checking double for Inf or NaN - how?

Hi,

I found the code below from
http://www.blitzbasic.com/Community/...hp?topic=55633

------
' Check if number is finite.
Local u:Double = 2 ' also works for floats

For Local n = 1 To 12
Print isfinite(u) + " " + u
u :* u
Next

Print
Print

u = u - u
Print isfinite(u) + " " + u
Function isfinite( x:Double ) ' assumes Intel byte order

Const EXP_BITS = %01111111111100 000000000000000 000

Local bits = ( Int Ptr Varptr x )[1] ' [0] for Mac?

Return ( bits & EXP_BITS ) <> EXP_BITS ' exponent is all 1s for
infinity or NaN

End Function
------

I need something like that - but the author writes that "This is intel
only. Anybody want to make it multiplatform? It shouldn't be difficult,
but I don't have a Mac".

The code above doesn't look like "standard C" to me... But I would like
this function to work *preferable* under both linux, mac and windows
pc's....

My guess is that the code should be changed to something like:

int(double testval)
{
Const EXP_BITS = %01111111111100 000000000000000 000

return (testval && EXP_BITS); /* returns either 0 or 1 ? */
}

But I guess EXP_BITS is completely wrong defined, so how to make it work
- and are there better existing ways to check for Inf or NaN???

It would be nice with 2 functions: One that tests for plus/minus Inf and
one that checks for NaN, if there's any difference? I didn't really
understood the bit-pattern-difference between NaN and Inf...
Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
May 18 '06
55 8355
Gordon Burditt wrote:
Richard Heathfield <in*****@invali d.invalid> wrote:
Malcolm said:
"jacob navia" <ja***@jacob.re mcomp.fr> wrote
Malcolm a écrit :
> "Richard Heathfield" <in*****@invali d.invalid> wrote

No, Richard Heathfield didn't write any of the stuff quoted in

and I didn't have anything to do with prior articles in this thread.

If you look back at the original (long gone from here), you will
find their is no material preceded by n+1 '>'s, where n is the
number of '>'s preceding the Heathfield attribution. The system is
self correcting, and has sufficient redundancy to detect careless
snipping, as above.

Proper netiquette is always topical. Think correcting children.

--
news:news.annou nce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
Jun 3 '06 #51
2006-06-03 <12************ *@corp.supernew s.com>, Gordon Burditt wrote:
In article <0K************ *************** ***@bt.com>,
Richard Heathfield <in*****@invali d.invalid> wrote:
Malcolm said:
"jacob navia" <ja***@jacob.re mcomp.fr> wrote
Malcolm a écrit :
> "Richard Heathfield" <in*****@invali d.invalid> wrote

No, Richard Heathfield didn't write any of the stuff quoted in your article.

and I didn't have anything to do with prior articles in this thread.

The problem is that your solution [snip all attributions] is worse than
the problem. You should ONLY snip attributions that don't apply to
quoted text.
Jun 3 '06 #52
go***********@b urditt.org (Gordon Burditt) writes:
In article <0K************ *************** ***@bt.com>,
Richard Heathfield <in*****@invali d.invalid> wrote:
Malcolm said:
"jacob navia" <ja***@jacob.re mcomp.fr> wrote
Malcolm a écrit :
> "Richard Heathfield" <in*****@invali d.invalid> wrote

No, Richard Heathfield didn't write any of the stuff quoted in your article.

and I didn't have anything to do with prior articles in this thread.

Somebody made the minor mistake of failing to snip a single
attribution line after having snipped all the corresponding text.
Richard pointed it out, and the whole thing was resolved without
threats or lawsuits.

You, on the other hand, repeatedly, consistently, and *deliberately*
make the far worse mistake of snipping all attributions, making
discussions more difficult to follow for everyone. I don't quite
agree with CBFalconer's statement in another thread that this is
plagiarism, but it is extremely rude.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 3 '06 #53
Keith Thompson wrote:
.... snip ...
You, on the other hand, repeatedly, consistently, and *deliberately*
make the far worse mistake of snipping all attributions, making
discussions more difficult to follow for everyone. I don't quite
agree with CBFalconer's statement in another thread that this is
plagiarism, but it is extremely rude.

I said it "was tantamount to plagiarism". Several nits there.

--
news:news.annou nce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

Jun 3 '06 #54

Gordon Burditt said:
Richard Heathfield wrote:
Malcolm said:
jacob navia wrote
Malcolm a écrit :
> "Richard Heathfield" wrote

No, Richard Heathfield didn't write any of the stuff quoted in your
article.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jun 3 '06 #55
CBFalconer <cb********@yah oo.com> writes:
Keith Thompson wrote:

... snip ...

You, on the other hand, repeatedly, consistently, and *deliberately*
make the far worse mistake of snipping all attributions, making
discussions more difficult to follow for everyone. I don't quite
agree with CBFalconer's statement in another thread that this is
plagiarism, but it is extremely rude.

I said it "was tantamount to plagiarism". Several nits there.

You also wrote:

| As I pointed out, quoting without attribution is effectively
| plagiarism. Every newsreader of which I am aware will construct the
| attribution lines automatically. There is no need to steal the
| words of others.

which is a stronger claim than "tantamount to plagiarism".

If he were posting others' remarks without marking them as quotations,
making them appear to be his own words, that would be plagiarism. In
my humble opinion, what he's actually doing is merely rude; there's no
appearance that other poster's words are actually his.

But I acknowedge that you didn't say that it actually *is* plagiarism,
and I don't think it's that important a point anyway. Plagiarism is a
legal term, and nobody is seriously threatening legal action. We're
both in complete agreement that he needs to stop snipping attributions
and/or give us a decent explanation (which he has so far failed to
do).

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 3 '06 #56

This thread has been closed and replies have been disabled. Please start a new discussion.