LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

float to mantissa and exponent

Hello,
that's my first post in the forum, I don't see the problem with my small VI.
I want to get mantissa and exponent from a float (with power of 10)
So I made the following VI but for some input values like 1E-11,1E-12,1E-13,1E-14 it returns 10.0 for the mantissa instead of 1.0
which is a real problem for the rest of my code.
If I look carefully during execution, I see that comparison  1 more or equal to 1 is false !!!
I suspect that 1 is not really 1.0 but 0.999999999

Any explanation ?

0 Kudos
Message 1 of 9
(8,464 Views)
You will always have trouble comparing doubles with values that are very close to eachother.  There is no exact way to store decimal fractions in binary.  The round off is exceedingly small, but can cause problems as you have demonstrated.

Any reason why you are not using the builtin Mantissa & Exponent function?  You can find it in Programming>>Numeric>>Data Manipulation.
0 Kudos
Message 2 of 9
(8,457 Views)
Thanks for your reply.
The built-in Mantissa & Exponent function returns power of 2 and I need power of 10 (I work with decades and Log10)

0 Kudos
Message 3 of 9
(8,450 Views)
I made a little example, how you can avoid those iterative multiplying of small values. So it should be faster and more exact.
Greets, Dave
Greets, Dave
Message 4 of 9
(8,436 Views)
This morning a colleague suggested me a different way to do and it's exactly the same as you.
Problem solved
Thanks everybody
0 Kudos
Message 5 of 9
(8,432 Views)

ello there..

i have some problems while using the mantissa and exponent. i want to convert hexadecimal value which is FF80000 to floating point. suppose i will get -0.1 but what happen is i will get 340282366920938463000000000000000000000. i have read some information on IEEE 754 format floating point number. i am confuse by the sentence of E is the two's complement exponent with an offset of 127 i.e. an exponent of zero is represented by 127, an exponent of 1 by 128 etc.

0 Kudos
Message 6 of 9
(8,278 Views)
Hi gdah,

well, if your hex code is really IEEE754 then a typecast to SGL should do the trick.
But: FF800000 isn't -0.1 in IEEE754-SGL, it should be something like BDCCCCCD!

See attachment with examples!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 9
(8,266 Views)
thank you for yr information..but actually the data ff800000 is received from the hardware. i must get -0.1 to make sure my data response is correct. i didn't have any problem to receive other data such as 230, 3.0 ..but when it come with -ve value my data response become wrong. is it because of my coding of data response or because of the mantissa itself??..plz help me...i'm using labview 8.2 
0 Kudos
Message 8 of 9
(8,242 Views)
 
 

I received this question from Judy by Email, but because of probably public interest I post this here again:


Hi David,

I couldn't read the vi because i don't have vi editor.
Is it possible that you send it to me in a txt file for the solution you posted up there.
Is it written in C language?
This is the solution you put there:

http://forums.ni.com/ni/board/message?board.id=170&message.id=206482 

 

 

Thank you very much for your help.

 

 

Judy

 

 

 

Hi Judy,

 

 

there are some things to explain. A file with the extension .vi is a so called „virtual instrument“, which unifies the User interface and the program logic in one file. There are many more properties a VI has. To edit a VI, you need LabView. You can download a free (limited) version of LabView here.

 

 

My little VI is shown in the picture below, the upper part shows the block diagram (program logic), the lower part is the front panel (user interface).

 

 

 


The code can be translated into some text based pseudo- code as follows:

 

 

//###############  PSEUDO CODE  ##########################

 

 

 

 

 

Var

 

 

            Float, LogX, Exponent, 10^x, Mantissa : Double;

 

 

 

 

 

Begin

 

 

            LogX := Logarithm_Base_10 (Float);

 

 

            Exponent := RoundToMinusInfinity (LogX);

 

 

            10^x := Power_of_10 (-1*Exponent);

 

 

            Mantissa := Float * 10^x;

 

 

End.

 

 

//###############  PSEUDO CODE  ##########################

 

 

Perhaps you can use this to solve your problem.

 

 

Greets, Dave

 

 

 

 

 



Message Edited by daveTW on 02-28-2008 11:02 AM

Greets, Dave
0 Kudos
Message 9 of 9
(7,860 Views)