cc-tweaked / Cobalt

A re-entrant fork of LuaJ
Other
72 stars 13 forks source link

Fix string.format "q" option handling of infinity and NaN #73

Closed Kan18 closed 1 year ago

Kan18 commented 1 year ago

The q specifier should format numbers such that they are a valid constant in Lua code. Previously, Infinity and NaN fell back to Double.toHexString which returns "Infinity" or "NaN", so these cases should be handled separately (matching PUC Lua behavior here).

SquidDev commented 1 year ago

Mostly noting this down because I was curious what the right behaviour was here:

I kinda wonder if we should do this properly and add support for floating point hex literals.

SquidDev commented 1 year ago

I've added support for hex literals, but occurs to me doing %q properly also requires supporting %a/%A (or at least a subset of it). This doesn't actually look too hard to get right, which is a relief at least.

SquidDev commented 1 year ago

Sorry for the delay in looking at this, looks good to me! Thank you <3.