473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 "What about NaN?"
Print

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

Const EXP_BITS = %01111111111100000000000000000000

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 = %01111111111100000000000000000000

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 8247
Gordon Burditt wrote:
Richard Heathfield <in*****@invalid.invalid> wrote:
Malcolm said:
"jacob navia" <ja***@jacob.remcomp.fr> wrote
Malcolm a écrit :
> "Richard Heathfield" <in*****@invalid.invalid> wrote


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


This is a perfect example of why attribution = misattribution,
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.

--
Some informative links:
news:news.announce.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.supernews.com>, Gordon Burditt wrote:
In article <0K******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
Malcolm said:
"jacob navia" <ja***@jacob.remcomp.fr> wrote
Malcolm a écrit :
> "Richard Heathfield" <in*****@invalid.invalid> wrote


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


This is a perfect example of why attribution = misattribution,
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***********@burditt.org (Gordon Burditt) writes:
In article <0K******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
Malcolm said:
"jacob navia" <ja***@jacob.remcomp.fr> wrote
Malcolm a écrit :
> "Richard Heathfield" <in*****@invalid.invalid> wrote


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


This is a perfect example of why attribution = misattribution,
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.

Stop snipping attributions.

--
Keith Thompson (The_Other_Keith) 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.

--
Some informative links:
news:news.announce.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
[Attributions have received a shave and a haircut.]

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.


This is a perfect example of why attribution = misattribution,


No, it's a perfect example of why misattribution = misattribution.

--
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********@yahoo.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_Keith) 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.

Similar topics

4
by: Leo P. | last post by:
I am trying to write a spelling checker. Specifically the part that suggests words. From what I've read online, it seems like the preferred way to do this, is to find the double metaphone...
3
by: Guy Robinson | last post by:
I have the code below which parses an expression string and creates tokens. Can anyone suggest the best of error checking for things like: Valid variable only obj.attribute -whitespace allowed...
6
by: Web Developer | last post by:
Hi, I come across the term "type checking" very often in my readings on C++, and have never heard it in Java. Besides the simplistic answer that it checks the "type", what more does it mean? ...
6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
21
by: jacob navia | last post by:
Many compilers check printf for errors, lcc-win32 too. But there are other functions that would be worth to check, specially memset. Memset is used mainly to clear a memory zone, receiving a...
11
by: utab | last post by:
Dear all, I have a simple template to convert its argument to a string: template<typename T> string AtoStr(T t){ ostringstream sstrm; sstrm << t; return sstrm.str(); }
2
by: Mike | last post by:
Hello, Ok I have 2 classes in my project, one is the main form and one is a connection class, at a certain event on my main form a new instance is made of the connection class, and a reference...
4
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if that found sub-string is inside single-quotes or...
1
by: powerej | last post by:
program is suppose to ask for an input from 1-8, if the user enters a number outside of this range than it will continue to ask until it does, something is wrong and i cant seem to figure it out, i...
9
by: pereges | last post by:
Hi, I'm trying to write a macro for the relative difference function which is used to check the close enough floating point values. Is this correct way to write it ? : #define max(x, y) ((x)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.