initialize a rational from a decimal string

edA-qa mort-ora-y eda-qa at disemia.com
Tue Mar 12 05:38:33 CET 2013


I'm looking for a way to initialize a rational from a decimal string. I
thought it might be a common task but I don't see any function which
would do this. Is there such a function?

Examples:
0.97 => 97/100
1.5 => 3/2
3.89e100 => 389/1

What I do now is parse the three parts of the decimal (XXX.YYYeZZZ) and
then manually assemble the bits. This involves a lot of calculations
however, in particular that fractional part as I need to loop over the
numbers multiplying by 10. Is there a better way?

-- 
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://gmplib.org/list-archives/gmp-discuss/attachments/20130312/fe155071/attachment.bin>


More information about the gmp-discuss mailing list