runtime icon indicating copy to clipboard operation
runtime copied to clipboard

All numbers should just be floats

Open vincent99 opened this issue 2 years ago • 2 comments

The intricacies of when a variable is an int vs a float is confusing since you don't declare the type anywhere. JS/JSON/YAML (mostly/effectively) just have a single number type.

This will fail because foos is implicitly an int:

args: {
  foos: 4
}
...

acorn run ... --foos=4.5

Numbers should just all be floats internally.

vincent99 avatar Aug 02 '22 05:08 vincent99

I would argue, that using floats by default is a bad choice. Floats have imprecision and thus, you specify something like: acorn run ... --foos=12378712311112331233, and the conversion to float will create an imprecision as you can see in this snipped: https://go.dev/play/p/nkMesfzt6tW

hikhvar avatar Aug 05 '22 07:08 hikhvar

All integers <2^53 are exactly representable as a 64-bit float (your example is ~2^60).

Above that storing numbers as "integers" still leads to hard to reproduce recipient- & value-dependent trouble. e.g. passing through JSON or in a UI (which we will have...) because JS only has "numbers" (64-bit float).

If you're dealing with numbers that big (9 quadrillion+) the only reliable way to transmit them is as strings.

I do think the parser could give you a useful error and stop you if you try though.

vincent99 avatar Aug 05 '22 08:08 vincent99

moving out of v0.4.0 because i dont think @ibuildthecloud will get to it in october

cjellick avatar Oct 05 '22 16:10 cjellick

assigning to @ibuildthecloud because I bucket this as part of the AML work

cjellick avatar Oct 05 '22 16:10 cjellick