Henrik Grubbstr?m (Lysator) @ Pike (-) developers forum wrote:
+#define sizeNUM(v) (8*sizeof(v)*4/10+1+1)
^^^^^^^^^^^^^^^^^^^^
It'd be nice with a comment explaining the various integers above.
:-). I'll have to rethink what they mean, I figured this out a very long time ago, and simply reused it time and again.
INT32 org;
^^^^^
You should probably have INT_TYPE here; otherwise there'll be problems with semi-large integers on 64-bit architectures.
Well, for one, what is the largest integer type to be expected in the svalue (without bignums)? Is that INT_TYPE instead of INT32?
- case T_FLOAT: {
- char buf[sizeNUM(double)*2];
^^^^^^^^^^^^^^^^^
Is this safe? What about the exponent?
The number of decimal digits plus one to represent an integer of type x is:
sizeNUM(x)
This implies that to represent an equal number of bits in the mantisse and exponent is:
sizeNUM(mantisse in bytes) + sizeNUM(exponent in bytes)
and size (mantisse+exponent) in bytes is sizeof(double) hence by approximating for a double that the number of digits needed to represent it is:
sizeNUM(double) * 2
should normally overestimate the total maximum stringsize by roughly a factor of two, which is a safe margin for unexpected floating point formatting options. Then again, we could start using snprintf there.