Converting a decimal string to mpq_t

Anders Andersson pipatron at gmail.com
Mon Apr 28 21:54:34 CEST 2025


Good evening! I wanted to convert a simple decimal string such as
"0.1" to an mpq_t but I can't find a way to do it even though an mpq_t
should be able to represent every such number exactly in every base,
except possibly NaN and Inf.

Do I have to write my own parser or do you have any ideas? Have I
missed something obvious?

If I manage to summon the strength to write such a function, would it
be a good idea to extend mpq_set_str to handle floating point input?


// Anders


More information about the gmp-discuss mailing list