inkle / ink

inkle's open source scripting language for writing interactive narrative.
http://www.inklestudios.com/ink
MIT License
4.14k stars 494 forks source link

Float printing #842

Open premek opened 1 year ago

premek commented 1 year ago

I was trying to figure out how many decimal places are printed for floats and it seems to be a bit inconsistent, some examples below:

0.9999999     =  {0.9999999}
0.99999991    =  {0.99999991}
0.99999992    =  {0.99999992}
0.99999997    =  {0.99999997}
0.99999998    =  {0.99999998}
@
0.000000000001=  {0.000000000001}
1.000000009   =  {1.000000009}
1.00000009    =  {1.00000009}
1.00000006    =  {1.00000006}
1.00000005    =  {1.00000005}
1.00000004    =  {1.00000004}
@
2.0000004    =  {2.0000004}
2.0000005    =  {2.0000005}
2.0000006    =  {2.0000006}

2.00000009    =  {2.00000009}
2.00000005    =  {2.00000005}
2.00000004    =  {2.00000004}

outputs

0.9999999 = 0.9999999
0.99999991 = 0.9999999
0.99999992 = 0.99999994
0.99999997 = 0.99999994
0.99999998 = 1
@
0.000000000001= 1E-12
1.000000009 = 1
1.00000009 = 1.0000001
1.00000006 = 1.0000001
1.00000005 = 1
1.00000004 = 1
@
2.0000004 = 2.0000005
2.0000005 = 2.0000005
2.0000006 = 2.0000007
2.00000009 = 2
2.00000005 = 2
2.00000004 = 2

Inky version: 0.14.1

ink version: 1.1.1

inkjs version: 2.1.0

joethephish commented 1 year ago

In the ink runtime this is just the default C# behaviour (see this line: https://github.com/inkle/ink/blob/6a512190365002f54bd501b0863ded40123cb8e5/ink-engine-runtime/Value.cs#L94).

I suspect it’s similar in inkjs…

premek commented 1 year ago

it seems it could even be "culture" (locale) dependent, is that intended?

feel free to close if this is not a bug

thank you