vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
533 stars 89 forks source link

`format` does not properly handle the `ll` (long long) specifier #405

Closed charlesstaats closed 7 months ago

charlesstaats commented 7 months ago

Example:

format('%llx', intMax);

expected output: 7ffffffffffffffd actual output: x

Note that the '%x' format string yields fffffffd, which conforms to the standard but nevertheless might be surprising to some people (in particular, me before I did additional research).

johncbowman commented 7 months ago

Thanks for reporting this. Actually, the int type in Asymptote is supposed to be the highest precision native integer (normally 64 bits) so for consistency, format should always enforce ll. In fact, an explicit 'll' doesn't really make sense from the point of view of the Asymptote machine (which, except for the bitwise functions AND, OR, XOR, NOT, CLZ, and CTZ pretends to be unaware of bit representations). So the desired behavour should be:

format("%x",intMax); 7ffffffffffffffd

format("%x",intMin); 8000000000000000

format("%d",intMax); 9223372036854775805

format("%d",intMin); -9223372036854775808

In fact the current version of Asymptote tries to turn 1 trillion dollars into a huge loss: format("$%'d",1000000000000); $-727,379,968

With commit 488d80962c76cc60629f590e34b350459ea59621, the correct result is produced: format("$%'d",1000000000000); $1,000,000,000,000