I've stumbled on this before, but ignored it, because I didn't have the time to isolate it and provide a Nim issue about it. But now I got caught by this bug again, so it's time to at least file an issue here.
If one defines a variable as const that has an associated type, the type information will be lost by the time this variable is used in some computation. If the type contains SI prefixes this is especially dangerous, because one misses conversion factors. Raw type information is a (comparatively) minor issue, because it would at least show up as a CT error due to missing types (which still might happen of course, but in cases where the types match regardless (i.e. just a computation and manual conversion to float) the numbers are plain wrong.
const g_aγ = 1e-10.GeV⁻¹
let x = g_aγ * 1.0.eV²
will result in x of type eV² and the conversion factor of 1e-9 missing from the result.
I've stumbled on this before, but ignored it, because I didn't have the time to isolate it and provide a Nim issue about it. But now I got caught by this bug again, so it's time to at least file an issue here.
If one defines a variable as
const
that has an associated type, the type information will be lost by the time this variable is used in some computation. If the type contains SI prefixes this is especially dangerous, because one misses conversion factors. Raw type information is a (comparatively) minor issue, because it would at least show up as a CT error due to missing types (which still might happen of course, but in cases where the types match regardless (i.e. just a computation and manual conversion to float) the numbers are plain wrong.will result in
x
of typeeV²
and the conversion factor of 1e-9 missing from the result.