0

I am trying to parse a file containing some floating point test vectors in MATLAB.

Here is part of the file:

b32+    +1.7FFFFFP127   -1.7FFFFFP127   +0.0P0  
b32+    +1.000000P0 -1.6D0976P9 -1.6CC976P9 
b32+    +1.000000P-126  -1.000000P-126  +0.0P0  
b32+    -1.7FFFFFP127   +1.7FFFFFP127   +0.0P0  
b32-    -1.7FFFFFP127   -1.7FFFFFP127   +0.0P0  
b32-    +1.000000P0 -1.000000P0 +1.000000P1 
b32-    -1.7C3AB6P14    +1.000000P0 -1.7C3CB6P14    
b32-    +1.2F0948P14    +1.000000P0 +1.2F0748P14    
b32-    -1.000000P-126  +1.000000P-126  -1.000000P-125  
b32-    +1.000000P-126  +1.000000P-126  +0.0P0  
b32-    -1.000000P-126  +1.0410ADP-103  -1.0410AEP-103  
b32-    +1.7FFFFFP127   +1.7FFFFFP127   +0.0P0  
b32*    +1.12D2C6P92    -1.000000P0 -1.12D2C6P92    
b32*    +1.7FFFFFP127   -1.000000P0 -1.7FFFFFP127   
b32*    -1.7FFFFFP127   +1.000000P0 -1.7FFFFFP127   
b32*    -1.5FEA32P-51   +1.000000P0 -1.5FEA32P-51   
b32*    -1.000000P-126  +1.000000P0 -1.000000P-126  
b32*    -1.000000P0 +1.000000P0 -1.000000P0 
b32*    +1.000000P0 +1.000000P0 +1.000000P0 
b32*    +1.000000P-126  +1.000000P0 +1.000000P-126  
b32*    +1.000000P-126  +1.7FFFFFP127   +1.7FFFFFP1 

Basically I don't know how to parse this file because of the mixed data type.

There are three possible floating point operations shown in this file (addition: b32+, subtraction: b32-, and multiplication: b32*). The first two numbers are the operands and the last number is the result.

I want to format the numbers in 32-bit floating point format afterwards (which I could figure out probably). The issue is that I don't know how to get things like 'b32+', and then the numbers into variables in order to convert them into standard floating point format.

I plan to implement an algorithm for the numbers where it looks at the sign (+/-) and sets the sign bit based upon that. Looks at the hex between the '.' and the 'P' and sets that as the significand. Then take the number after the P as the unbiased exponent. Then I plan to repeat this procedure for the other numbers.

Thank you!

Öö Tiib
  • 10,809
  • 25
  • 44
Veridian
  • 3,531
  • 12
  • 46
  • 80
  • Why is this tagged with [tag:c++] and [tag:c]? – johnsyweb Feb 23 '13 at 01:36
  • Just in case someone in that community comes up with a better c or c+ based solution. – Veridian Feb 23 '13 at 01:39
  • see http://stackoverflow.com/questions/2062259/using-c-c-to-efficiently-de-serialize-a-string-comprised-of-floats-tokens-and?rq=1 – Öö Tiib Feb 23 '13 at 02:25
  • Thank you for your responses. I am not sure how to pull out parts of the string for something like +1.5FEA32P-51. Basically I would want to get back the following: +1, 5FEA32, -51 – Veridian Feb 23 '13 at 02:40

1 Answers1

0

This was actually what I was looking for:

c = sscanf(line,'b32%c %c%c.%xP%d %c%c.%xP%d %c%c.%xP%d',[1,inf]);
Veridian
  • 3,531
  • 12
  • 46
  • 80