%Qf in gmp_printf

Pedro Gimeno gmpdiscuss at formauri.es
Wed Apr 6 20:09:12 UTC 2016


paul zimmermann wrote, On 2016-04-06 15:12:> isn't the code below more efficient?
> 
> mpz_t div = (num * 10^decimals) / den
> str = out (div)
> print head (str, len(str) - decimals)
> print "."
> print tail (str, decimals)

I don't know. It most probably would. Due to having worked with certain very restricted embedded systems recently where speed is rarely an issue, I'm very prone to favour memory optimization over speed optimization. I understand that that's not what GMP is about, so please excuse if my algorithm is likely to be inefficient speed wise. Memory wise, this algorithm needs to store the whole number up to the required precision twice, one in base 2^(limb bits) and one in base 10, but that's not a concern for GMP.



More information about the gmp-discuss mailing list