From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert float to rational

Solved!
Go to solution

Hello,

The TIFF tag header protocol requires a data type I am not really conversant with, the Rational Data type: http://en.wikipedia.org/wiki/Rational_data_type

 

I need to convert double precision numbers to this data type, e.g. 24.5 needs to be a ratio of two integers: {49,2}. Is there an existing LabVIEW algorithm to perform this operation? All my NI searches keep resulting in Rational ClearCase or Rational Array interpolation. I seem to have found a lot of the theory behind this: http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions

 

But, is this implemented in labVIEW already, or should I implement the above-referenced c-code?

 

Thanks,

Mello


Data Science Automation

CTA, CLA, CLED
SHAZAM!
Message 1 of 10
(5,195 Views)

That implementation is not in LabVIEW. Perhaps you may wish to post a suggestion to add it to a future release of LabVIEW.

 

If you have C code that will do it then you can call it using Call Library Function Node . You'll either need a DLL or you'll need to create one. Or, you can just convert the code to LabVIEW. 

Message Edited by smercurio_fc on 02-24-2010 11:01 AM
Message 2 of 10
(5,188 Views)

Thank you smercurio, I think I am going to go with the workaround/kluge method of multiplying by a power of ten and truncating:

23.5  => {23500, 1000}

 

I will add a suggestion that a more elegant solution be made part of the NI math or numeric palettes.

 

-Mello


Data Science Automation

CTA, CLA, CLED
SHAZAM!
0 Kudos
Message 3 of 10
(5,166 Views)

Hi,

 

Maybe you can make use of Altenbach's fraction code in the last post in this  link can help you.

 

cheers

 

David

Message Edited by David Crawford on 02-24-2010 06:09 PM
Message 4 of 10
(5,159 Views)
Solution
Accepted by topic author Mellobuck

This should be possible if you have MathScript available.

 

 see attached ( LV 8.6.1)

 

dbl to Rational.JPG

Message Edited by Phillip Brooks on 02-24-2010 02:33 PM

Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Message 5 of 10
(5,141 Views)

Thanks Phillip!

A Matlab user such as myself should have thought of that method 🙂


Data Science Automation

CTA, CLA, CLED
SHAZAM!
0 Kudos
Message 6 of 10
(5,129 Views)
Glad to be of help. KAPOW!

Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Message 7 of 10
(5,126 Views)

Phillip Brooks wrote:

This should be possible if you have MathScript available.


Neat. Didn't know that function existed in MathScript.

 

Note that for LV 2009 one requires a separate license for MathScript. There was a big long debate about this when 2009 was released. Every bitched and moaned. It was fun reading. Not so much fun for those who had to shell out more cash for it though.

Message 8 of 10
(5,093 Views)

I was curious if there were other ways to do this and found that Scilab combined with the LabVIEW Gateway works quite well. The 'rat' function is available in Scilab; Scilab and the LabVIEW gateway were both easy to install...

 

 

http://www.scilab.org/products/other/labview_gateway


Message Edited by Phillip Brooks on 03-04-2010 08:29 AM

Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Message 9 of 10
(5,005 Views)

Since LabVIEW has a vi to return the greatest common multiple, it's not hard to make a vi to get to fractions. This snippet solves a similiar problem of converting the floating point number to string whole number plus a fraction.Number to string with fraction.png

0 Kudos
Message 10 of 10
(4,144 Views)