Floating Point and 32 bit comparision

A

Thread Starter

Atul Shah

The new Micro PLC's have come with 32 arithmatic in place of floating point. I would like to know the following:
1. Comparision in terms of accuracy for analog value in either cases.
2. Pros and Cons of 32-bit data value and Floating point data value.
3. Why to select for Floating point or 32-bit data value processing?
4. How to achieve, in general, floating point w.r.t. 32-bit data?
5. What is the format of the two types?
6. Advantages of one format over the other, in terms of data storage in PLC's.
 
S

Simon Martin

I don't know the processor being used, but talking in generalities we get something like the following

1) 32 Floating Point

Number is separeted into 24 bit mantissa and 8 bit exponent (some use 2s complement, some use sign and magnitude, on one or either, but the previous is usually correct). This means that you
only have 24 significant bits of data. This means that you can only specify completely and unequivocally 24 bit numbers shifted left or
right by powers of 2 specified by the exponent. This means that as far as the processor is concerned 16777215 has the same representation 16777215.1, 16777215.2, etc.

2) 32 bit integer

This number representation is a straight bit value (2s complement, unsigned, 1s complement, sign and magnitude, etc). In effect you have 32 bits of data to play around and every number has a unique representation, Unfortunately you cannot represent fractions, or numbers greater than 4294967295 (2^32 - 1).

Rules of thumb:

1) if a great number range has to be covered, and you can live with the fact that you only have 24 significant bits, then use floating point

2) if you have a small dynamic range and/or you need more than 24 significant bits, then use 32 bit floating point

3) if you have a large dynamic rante and/or you need more than 32 significant bits then you need to design your own representation.

Debian GNU User
Simon Martin
Project Manager
Isys
mailto: [email protected]

There is a chasm of carbon and silicon the software cannot bridge
 
J

John Waalkes

> The new Micro PLC's have come with 32 arithmatic in place of floating point. I would like to know the following:

> 1. Comparision in terms of accuracy for analog value in either cases.

Well a 32 bit *integer* is always accurate, since you can't have a fractional part. Within its range of course.

You can't say the same thing for floating point, IEEE uses 64 bits (8 bytes) to represent a floating point number (note: this is twice the storage requirments as a 32 bit number).

Of these bits, 1 is for the sign bit, 11 for the exponent bits, and 52 for the mantissa.

The rub here is that even with 52 bits for the fractional part, you can't have a bit pattern for every possible fraction (does this make sense?).

In other words, you can't stuff an infinite number of possible fractions in 52 bits...

A good explaination on this can be found at:

http://support.microsoft.com/support/kb/articles/Q42/9/80.asp

I apologize in advance for the MS link...



> 2. Pros and Cons of 32-bit data value and Floating point data value.

Well, if you can use a 32 bit integer for what you want, it's the way to go. For one thing, the storage space is half that of float. And CPU's are made for integer math, so it's much faster.


> 3. Why to select for Floating point or 32-bit data value processing?

I'm not sure what the question is, sorry.


> 4. How to achieve, in general, floating point w.r.t. 32-bit data?

Easy! For PLC's (I assume that's why you are here) you generally want two digits for the fractional part.

e.g. 123.45

So in the PLC, store your variable in a 32 bits as:

12345

And simply put the dot where you need it for displaying the data and such (the PLC isn't going to care that you are representing 123.45 as 12345 in memory).

To display your number and make it look like it was a floating point number in the PLC you would print it like this:

"eee" "." "ff"

In other words, take the number/100 and print that (the "eee" part), then print a ".", and then subtract what you got from number/100 from your original number

"ff" would equal number - (number/100)

Got it?


If you do have to have a float variable in the PLC for whatever reason, then do all of your math as 32 bit int until the last step, and that would be to divide your int result by 100 (for this example).

> 5. What is the format of the two types?

See the MS link posted previously.


> 6. Advantages of one format over the other, in terms of data storage in PLC's.

You should know that by now :)


Enjoy,

John Waalkes
SuSE Linux user :)
 
Top