473,883 Members | 1,697 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 8356
"jacob navia" <ja***@jacob.re mcomp.fr> wrote
Richard Heathfield a écrit :
jacob navia said:


"Portabilit y" for you means "taking the worst features of each
implementation" .

That's inevitable. The convoy travels at the speed of the slowest ship.

--
www.personal.leeds.ac.uk/~bgy1mm
May 20 '06 #41
Malcolm a écrit :
"Richard Heathfield" <in*****@invali d.invalid> wrote
pete said:

Richard Heathfield wrote:
C99 features are, quite simply, not even remotely as portable as C89
features.

I like the added restrictions of C99, such as no implicit int
and requiring protypes for all functions.


Likewise. Shame about the return value from main, but I stick it in
anyway,
of course.


Implicit int was a fossil and it's time it went.
However prototypes are just a nuisance. There's some case for them in a
header file, where they describe the interface to the file, but the only
reason for them in other places is to allow the compiler to check arguments
on one pass. A modern compiler should be intelligent enough to do this
without a prototype to help it along.


Please think a bit Malcom.

To know the argument for a function without prototypes the compiler
should have the source code for all functions, including those in the
libraries the program is using. This would imply that the source code
for all the system would have to be processed, loaded into memory,
before any checks could be done.

This is completely impossible, so *some* type of prototype declaration
is needed. In Pascal you have the 'interface' declarations, in C# you
have a similar construct... etc!

May 20 '06 #42
On 2006-05-20, jacob navia <ja***@jacob.re mcomp.fr> wrote:
Malcolm a écrit :
Implicit int was a fossil and it's time it went.
However prototypes are just a nuisance. There's some case for them in a
header file, where they describe the interface to the file, but the only
reason for them in other places is to allow the compiler to check arguments
on one pass. A modern compiler should be intelligent enough to do this
without a prototype to help it along.


Please think a bit Malcom.

To know the argument for a function without prototypes the compiler
should have the source code for all functions, including those in the
libraries the program is using. This would imply that the source code
for all the system would have to be processed, loaded into memory,
before any checks could be done.

This is completely impossible, so *some* type of prototype declaration
is needed. In Pascal you have the 'interface' declarations, in C# you
have a similar construct... etc!

Not to mention the fact that maintenance programmers want a prototype
to give them some idea of how a function works!

--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
Get your game faces on, because this is not a game.
May 20 '06 #43
"jacob navia" <ja***@jacob.re mcomp.fr> wrote
Malcolm a écrit :
"Richard Heathfield" <in*****@invali d.invalid> wrote

However prototypes are just a nuisance. There's some case for them in a
header file, where they describe the interface to the file, but the only
reason for them in other places is to allow the compiler to check
arguments on one pass. A modern compiler should be intelligent enough to
do this without a prototype to help it along.


Please think a bit Malcom.

To know the argument for a function without prototypes the compiler should
have the source code for all functions, including those in the libraries
the program is using. This would imply that the source code for all the
system would have to be processed, loaded into memory, before any checks
could be done.

This is completely impossible, so *some* type of prototype declaration is
needed. In Pascal you have the 'interface' declarations, in C# you have a
similar construct... etc!

The library should contain information about the signature of the functions
it contains.

The problem might be the weight of libraries without this feature, and no
way of retrieving information from them.
--
www.personal.leeds.ac.uk/~bgy1mm


May 21 '06 #44
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.

--
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)
May 21 '06 #45

"Richard Heathfield" <in*****@invali d.invalid> wrote in message
news:0K******** *************** *******@bt.com. ..
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.

Think of the attribution lines as prototypes.
Initially I included the bit about implicit int, but then I realised that
jacob navia hadn't
mentioned that point, so I snipped it. But I forgot to update the
attributions.

That's the problem when you have information in two places at once.
--
www.personal.leeds.ac.uk/~bgy1mm

May 21 '06 #46
Richard Heathfield 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.


You going to sue him?


Brian

May 21 '06 #47
Default User said:
Richard Heathfield 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.


You going to sue him?


I wasn't planning on it, no. I don't consider litigation to be the best way
to settle Usenet disagreements.

But having said that... with a name like Malcolm, he's probably Scottish -
so maybe I'll make an exception in his case. :-)

--
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)
May 21 '06 #48
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.

Also, this is off-topic for comp.lang.c. Is there a alt.flame.attri butions?

Gordon L. Burditt
Jun 3 '06 #49
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.

Also, this is off-topic for comp.lang.c. Is there a alt.flame.attri butions?


It was a simple case of forgetting to do a final snip after deleting the
last piece of Richard's text. It did not lead to major disputes the way
you claim.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Jun 3 '06 #50

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
11123
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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...
1
10836
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4211
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.