Jump to content
  • 0

GG Lua has broken floating point number support?


fllwr

Question

e.g. ((1592891810914 / 1000) == 1592891810) evaluates to true in GG

Obviously this is not the default behavior of Lua 5.3.

GG 99.0, arm64

GG_logcat_r99.0_16126_9_28.log.7z

 

In addition to broken division, converting fp number to string yields different result in GG.

print(1592891810914 * 0.001) gives out "1.592891810914E9" in GG, though it is "1592891810.914" in every other lua console I used.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • Administrators

Like in Java, first operand define type of operation.

So you need make it float:

((1592891810914.0 / 1000) == 1592891810) -- false

In the second case it is same.

1.592891810914E9 == 1592891810.914

 

Link to comment
Share on other sites

1 hour ago, Enyby said:

Like in Java, first operand define type of operation.

So you need make it float:


((1592891810914.0 / 1000) == 1592891810) -- false

In the second case it is same.

1.592891810914E9 == 1592891810.914

 

It doesn't make sense and violates Lua manual, because Lua has separate int-div // and fp-div /. (and no formal way to convert between int/fp)

 

I tested it in other Lua 5.3 build:

((1592891810914 / 1000) == 1592891810) => false

print(1592891810914 * 0.001) => "1592891810.914"

1.592891810914E9 == 1592891810.914 is a problem: it means string conversion is incompatible with other Lua build. (e.g. serialization creates different output)

 

>> ((1592891810914.0 / 1000) == 1592891810) -- false

This is not even a workaround because in practice, since variables could be int or fp.

Maybe +.0 or + -.0 can convert int to fp for variables...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.