Stream: beginners

Topic: Scientific notation


view this post on Zulip Brian Teague (Jan 18 2024 at 18:47):

Is this a bug?
1f64 * 1e-40 works, but just 1e-40 by itself causes a panic:

» 1f64 * 1e-40
0.0000000000000000000000000000000000000001 : F64
» 1e-40
panicked at 'Invalid decimal for float literal = 1e-40. This should be a type error!', crates/compiler/mono/src/ir/literal.rs:104:25

view this post on Zulip Brendan Hansknecht (Jan 18 2024 at 19:06):

Not a bug

view this post on Zulip Brendan Hansknecht (Jan 18 2024 at 19:06):

Needs a better error message though

view this post on Zulip Brendan Hansknecht (Jan 18 2024 at 19:07):

1e-40 is a Frac. The default Frac is Dec. It is too small to fit in Dec.

view this post on Zulip Brendan Hansknecht (Jan 18 2024 at 19:07):

When used with 1f64, 1e-40 is an f64. So it fits

view this post on Zulip Brendan Hansknecht (Jan 18 2024 at 19:08):

Would be great to file an issue on giving a good error here

view this post on Zulip Brian Carroll (Jan 18 2024 at 19:09):

Probably not a bug but the error message could be more helpful. The default type for a fractional number is Dec which is a 128-bit fixed point (not floating point) number. I can't remember how many decimal places it can accommodate but presumably less than 40.

view this post on Zulip Brian Carroll (Jan 18 2024 at 19:10):

Oh I was answering at the same time as Brendan :big_smile:

view this post on Zulip Brendan Hansknecht (Jan 18 2024 at 19:30):

18 places for anyone curious


Last updated: Jul 06 2025 at 12:14 UTC