News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Floating Point Scanner

Started by FlySky, October 07, 2010, 04:06:18 PM

Previous topic - Next topic

FlySky

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?


ToutEnMasm


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

jj2007

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.

clive

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.
It could be a random act of randomness. Those happen a lot as well.

raymond

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).
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

FlySky

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


clive

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
It could be a random act of randomness. Those happen a lot as well.

oex

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
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Gunther

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
Forgive your enemies, but never forget their names.

MichaelW

Testing for NaN would be meaningful only if you knew that the numbers are valid. A float holding a NaN is still a float.
eschew obfuscation