IEEE 64bit floating point

jdpenrod

Member
Join Date
Feb 2006
Location
Houston, Texas
Posts
1
does anyone have an example on how to convert a double precision (64bit) floating point number to single precision in a SLC500. i am polling an "accuload" with modbus and populating four integer files that make up the dp number. how do i get it to sp fp?
 
It can be done - but I have never done it and though I wish I had the time to tinker with it now, I don't.

If you aren't familiar with the floating point format used in the SLC, see this AB technote first:
http://domino.automation.rockwell.com/applications/kb/RAKB.nsf/0/85C2838CBFC456D285256AFB00695031?OpenDocument

Here is a really cool utility that lets you see exactly how a floating point number is represented in binary.

http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html


http://en.wikipedia.org/wiki/IEEE_floating-point_standard
 
Last edited:
I started thinking about how to do this after work and so this is what I banged out.

I tested it on a SLC5/05 and it seems to work OK for numbers such as PI, 999.99, 3.402823466E+38, 2, and 0. I think it will work for all double floats that are in the valid number range for a single float. If the number is bigger than 3.4032823E38 then this is not going to work - it will return infinity.

There is probably a better way to do it - but it appears to work. At least you can see how to do it.

This routine truncates the mantissa at 23 bits, IT DOES NOT ROUND.
Use it at your own risk - no warranty to accuracy is made.

Make sure you get your words in the right order into N207:0 thru N207:3.

(note: Ignore Rung 31. It was there for testing and it doesn't do anything for the conversion. I forgot to take it out before making the PDF and I'm too tired to redo it).
 
I had another thought on this particular problem. This is a simpler but more limited solution.

If you are absolutely sure that your double will not have an exponent larger than 38 or smaller than -38 then you can make it really simple.

Just map the bits from a 64 bit field to a 32 bit field (two consecutive integers) as shown and then use COP to move the two integers to a float. This doesnt provide any range checking but it is simple to do.

63 -> 31

62 -> 30

61 -> ignore

60 -> ignore

59 -> ignore

58 -> 29

57 -> 28

56 -> 27

55 -> 26

54 -> 25

53 -> 24

52 -> 23

51 -> 22

50 -> 21

49 -> 20

48 -> 19

47 -> 18

46 -> 17

45 -> 16

44 -> 15

43 -> 14

42 -> 13

41 -> 12

40 -> 11

39 -> 10

38 -> 9

37 -> 8

36 -> 7

35 -> 6

34 -> 5

33 -> 4

32 -> 3

31 -> 2

30 -> 1

29 -> 0

28 -> ignore

27 -> ignore

26 -> ignore

25 -> ignore

24 -> ignore

23 -> ignore

22 -> ignore

21 -> ignore

20 -> ignore

19 -> ignore

18 -> ignore

17 -> ignore

16 -> ignore

15 -> ignore

14 -> ignore

13 -> ignore

12 -> ignore

11 -> ignore

10 -> ignore

9 -> ignore

8 -> ignore

7 -> ignore

6 -> ignore

5 -> ignore

4 -> ignore

3 -> ignore

2 -> ignore

1 -> ignore

0 -> ignore
 

Similar Topics

Looking for some explanation/history between North American electrical symbols standards (how they relate, what are the latest, what is the...
Replies
3
Views
1,693
Hello! Long time lurker and gatherer of information - love this forum. I am trying to find some sort of tag naming standard if it exists...
Replies
18
Views
8,394
Dear friends across the pond, Does anyone know which one is the IEEE standard regarding the harmonics performance of the VSDs? Regards Nik
Replies
4
Views
2,112
OK, so I have a ControlLogix L61 Processor and I am communicating with a Veeder-Root 350+. I have established the comm and am getting valid data...
Replies
15
Views
5,528
Back
Top Bottom