You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider adding a compiler flag -vet-conversion to warn about implicit conversions that may result in loss of data, including converting integers to floats #5495
MIRSA discourages implicit conversions outright between integral and floating-point types.
GCC has the -Wconversion flag that can be used to warn about implicit conversions that may result in loss of data, including converting integers to floats.
// compile time values and types with implicit conversions
main :: proc() {
i :: 1000000160
f: f32 : i
fmt.printfln("% 20.1f", f) // 1000000128.0// i :: 1000000160
}
// with explicit typing constant and dynamic cast
main :: proc() {
f: f64
i: int : 9223372036854775807
f = cast(f64)i
fmt.printfln("% 20.1f", f) // 9223372036854775808.0// i : int : 9223372036854775807
}
// same as above but with a variable vs. constant for both
package main
import"core:fmt"
main :: proc() {
f: f64
i: int = 9223372036854775807
f = cast(f64)i
fmt.printfln("% 20.1f", f) // 9223372036854775808.0// i := 9223372036854775807
}