The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: FlySky on October 07, 2010, 04:06:18 PM

Title: Floating Point Scanner
Post by: FlySky on October 07, 2010, 04:06:18 PM
Hey guys,

I am just messing around with Floating point values and I am wondering the following.

I made an array of values all 4 bytes long but some are just decimal values while others represents real floating point values.
Now I am trying to pass the starting adress of the array to the source register and use it to browse through the array.
I want the scanner find the real floating point values and skip all others. Is there any instruction which can check if a value is a real floating point value?

Title: Re: Floating Point Scanner
Post by: ToutEnMasm on October 07, 2010, 04:18:39 PM

You need some fonctions of the crt library (c++ express)
The sample below use them
http://www.masm32.com/board/index.php?topic=11749.msg88731#msg88731
Title: Re: Floating Point Scanner
Post by: jj2007 on October 07, 2010, 05:18:34 PM
Quote from: FlySky on October 07, 2010, 04:06:18 PMIs there any instruction which can check if a value is a real floating point value?

No. The processor has no means to distinguish between a REAL4 and a DWORD.
Title: Re: Floating Point Scanner
Post by: clive on October 07, 2010, 06:19:54 PM
Quote from: jj2007
No. The processor has no means to distinguish between a REAL4 and a DWORD.

Or, for that matter any one/thing else, it's just a collection of 32-bits which you've attached some arbitrary meaning too. Sure you can look for patterns, or common values, or ASCII characters, but that's more of a judgment call.
Title: Re: Floating Point Scanner
Post by: raymond on October 08, 2010, 12:51:27 AM
QuoteIs there any instruction which can check if a value is a real floating point value?

Obviously, it all depends on your definition of a "real floating point value". If you provide us with a clear definition of what is and is not such a value (in the context of what you are trying to achieve), we would certainly be in a better position to possibly provide some solution(s).
Title: Re: Floating Point Scanner
Post by: FlySky on October 08, 2010, 05:22:37 PM
Hey there Raymond and the others,

Correct it depends on what I am calling a real floating point value.
Consider I am loading in the source adress the starting adress of an array:

They Array is defined as db '00 00 f8 3f 00 00 00 01 00 00 c8 42 00 00 00 0A',0

Searching 4 bytes aligned is chaning all 4 dwords, while I am searching for a way to grab the REAL4 (floats represented in hexadecimal).

3F800000 = 1. float
42C80000 = 100. float

Title: Re: Floating Point Scanner
Post by: clive on October 08, 2010, 05:36:15 PM
And
0x01000000 is 2.350989e-038
0x0A000000 is 6.162976e-033

So unless you "know" what a specific group of 32-bit is representing, it's going to be a tad difficult to determine if it is an integer or float, or something else.

Also 0x3F666666 is 0.9, or is it ASCII
Title: Re: Floating Point Scanner
Post by: oex on October 08, 2010, 05:56:46 PM
Maybe if there are patterns or known expected values you could do this (ie if all integer values and floating point values couldnt have the same value in your dataset).... ie 1.0, 1.0, 100.0, 1, 2, 3

However....

0.0 == 0

So there would be an obvious conflict here you couldnt determine....

Alternatively if you know the structure beforehand REAL4|REAL4|INT|REAL4 obviously this way the values can be found
Title: Re: Floating Point Scanner
Post by: Gunther on October 08, 2010, 07:19:41 PM
Hallo FlySky,

Clive is right with his answer: the entire question is a bit tricky, because a bit pattern is a bit pattern, is a bit pattern ... etc.

But you could try the following approach: The "string" is a C string (zero terminated). You can easy determine the string length. After that, build a loop and make several runs over the entire array:

1. Load for bytes as float value into the FPU (with fld dword ptr). It's either a number or a NaN. If you know the range of your REAL 4 values, this will give you important informations.
2. Load for bytes as integer values into the FPU (with fild dword ptr).

At least you could decide, is it a REAL 4 or an ordinary integer value. The rest is probably ASCII stuff.

Good luck.

Gunther
Title: Re: Floating Point Scanner
Post by: MichaelW on October 09, 2010, 03:04:11 AM
Testing for NaN would be meaningful only if you knew that the numbers are valid. A float holding a NaN is still a float.