initialize a rational from a decimal string

edA-qa mort-ora-y eda-qa at disemia.com
Tue Mar 12 19:06:21 CET 2013


On 12/03/13 18:57, Torbjorn Granlund wrote:
>   3.89e100 => 389/1
> Hm, are you sure about that last calculation?  :-)

Oops, that should be 3.89e2

> We don't provide a function for this.  Perhaps we should.

It'd be really convenient, but I have one now. ;)
I'll just through up a short blog article in case somebody else is
looking for this.

> Instead of repeatedly multiplying by 10, I'd suggest that you multiply
> by a suitable power of 10, which you'll need to figure out first.
> It does not matter too much if the power is minimal, as long as it is
> not very much too large.

Yes, from another poster I use strlen to figure out the exponent of 10.
My code will also have a cut-off point for the exponent, so beyond a few
hundred I'll switch to using a high-precision mpf instead.


-- 
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/c80c8745/attachment.bin>


More information about the gmp-discuss mailing list