473,883 Members | 1,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


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***********@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.


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_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.

--
Some informative links:
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
[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********@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.

Similar topics

4
9730
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 equivalent of a mispelled word, then to compute the mispelled word's distance from other words which have the same, or a similar metaphone equivalent. I've run into some problems with this approach. For example, "accommodation" has a metaphone code of...
3
1902
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 test( "ff*2/dd.r..ss r") #additional ..ss -invalid variable. test( "ff*$24..55/ddr") #double .. and $ -invalid number test( "ff*2/dd.r.ss r") #variable with double . -invalid variable
6
14325
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? WD
6
3342
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 my particular application. One of the advantages is that the _compiler_ can force inner matrix dimensions used in multiplication to agree. A _complie-time_ error will be triggered if you write A * B and the number of coluns in A does not equal the...
21
8808
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 pointer to the start, the value (most of the time zero) and the size of the memory array to clear. Problems appear when the size given is not the size of the object given as its first argument. For instance void fn(void)
11
5681
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
3756
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 to the main form is passed to its constructor. The connection class opens up a new thread and starts doing work in it, and adds collected data to the main form via a (cross-thread) control invoking delegate.
4
12798
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 double-quotes or not inside any quotes? If so how? Thanks in advance: Michael Yanowitz
1
1964
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 am stuck. Also my if else to see if the user catches the wave seems right to me but only works like half the time. I just really want to know what i am doing wrong here. import javax.swing.*; // gets option pane import...
9
284
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) (y) ? (x) : (y)) #define eq(a, b) max(fabs(a), fabs(b)) == 0.0 ? 0.0 : fabs(a - b) / (max(fabs(a), fabs(b)))
0
9933
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9781
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7960
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4210
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.