The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 float or int?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Mike Buess Posted - 01/09/2005 : 10:22:55 AM
Origin Version (Select Help-->About Origin): 7.5
Operating System: XP

I have some binary data files with the same format but some of the files contain 4-byte floating point values and others contain 4-byte integers. (None contain a mixture of float and int.) Is there a standard method for determining if a number is float or int? Now I read (OriginC) the first couple of values as float and decide if the results are reasonable using these criteria...

if( abs(float value)>1E36 ) too large so must be int;
if( abs(float value)<1E-36 && abs(float value) ) too small so must be int;

This works for the files I've tested but the cutoff values (1E36 and 1E-36) are rather arbitrary. I can't keep from thinking that a more reliable test exists.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 01/09/2005 10:37:06 AM
4   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 01/10/2005 : 2:14:08 PM
Thanks Hideo, I'll look into that.

Mike Buess
Origin WebRing Member
Hideo Fujii Posted - 01/10/2005 : 12:01:18 PM
Another possible "heuristics" may be to check if
there is ON bit in 2nd-9th bit (Exponent) area
assuming that your (positive) integer is always
smaller than 2^23 (fit within Mantissa area).

--Hideo Fujii
OriginLab




Edited by - Hideo Fujii on 01/10/2005 12:05:57 PM
Mike Buess Posted - 01/10/2005 : 11:30:19 AM
Thanks ML,
quote:
There is no reliable way to do this.
I was afraid of that. I'll look at the MS link anyway.
quote:
In general, it has got be a bad practice to stuff a value into 4-bytes without knowing at a later stage in which format the value is stored.
The data type is specified in a separate parameter file but that file might not be available in some cases and then you have to guess. Most of the time it's obvious from the resulting data that you've guessed wrong but I was trying to avoid the necessity of re-importing.

Mike Buess
Origin WebRing Member
ML Posted - 01/10/2005 : 10:55:03 AM
Hi Mike,

There is no reliable way to do this.

For a four-byte (=32 bit) storage, there are 2^32=4294967296 possible bit combinations. All of them are considered to be legal 4-byte integers by an x86 CPU, and it is only up to the person-program using a four-byte integer to determine whether the number makes sense or not. Note that this is true whether abs(float value) is greated than 1E36 or not or less than 1E-36 or not.

Here is one example:

The float value of 1.F (F at the end of the literal indicates that it is a float, not a double) is represented like this when looked at as a 4-byte integer (here shown in hex representation):

0x3F80 0000

In decimal this would be 66584576 . Who is to say whether 66584576 is a "bad" integer?

In general, it has got be a bad practice to stuff a value into 4-bytes without knowing at a later stage in which format the value is stored.

If you are intersted, here is from Microsoft's help the description of the float type in memory (this is IEEE standard):


http://support.microsoft.com/default.aspx?scid=kb en-us 36068


Note that not all combinations of 32bit values are considered legal float values, but most of them are (the legality can probably be inferred from Micorsoft's link above).

ML





The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000