$ perl -wE'printf"%.0e\n",2 ** -1074'
Yes, if you know in advance the minimum number of digits needed then you can certainly feed that precision to printf() as you have done.
But, in general, one doesn't know that number.
For the given example, "%.0e" is fine because the following condition is true when $prec is 0:
sprintf "%.${prec}e", 2 ** -1074 == 2 ** -1074
But replace "2 ** -1074" with "3 ** 0.5", and the condition is untrue if $prec is 0.
What's the minimum value for $prec that will render the condition true for 3 ** 0.5 ? I haven't checked, but if nvtype is "double" it's probably 16, definitely not greater than 16, and unlikely to be less than 15.
Python3 (and the algorithm I've coded up) will output that minimum precision, without the need for anyone to calculate a "$prec" and feed it to printf().
Only thing I don't currently have is access to a widely available and well tested implementation of the algorithm for "long double" and "__float128" NVs - one that I can use to double-check that my own implementation is behaving correctly and standardizing the output appropriately.
And that's what I'm seeking.
Cheers, Rob
| [reply] [d/l] |