Replies: 3 comments 2 replies
-
This is not a bug. Float literals e.g In arithmetic ops such as addition the literal will be automatically casted into left operand type, so
If right operand type has bigger size than left one the resulting type will be bigger type (
I agree that this topic is poorly covered in the documentation. |
Beta Was this translation helpful? Give feedback.
-
Also helps wondering "what golang does?". Golang does not accept adding float32 and float64, you need to cast and "type more code". For your V section: v3 := f32(1.5)
v4 := 0.5
v5 := v3 + v4 Go requires do a specific cast on v3 (or v4) to get v5, otherwise does not compile the program a sends a message v3 := float32(1.5)
v4 := 0.5
v5 := float64(v3) + v4
fmt.Printf("v3 type is %T\n", v3) // float32
fmt.Printf("v4 type is %T\n", v4) // float64
fmt.Printf("v5 type is %T\n", v5) // float64 My personal opinion is V helps user preventing to do casts, but user should be aware. but always V lets you do your cast (as mandatory golang requires to) if you decide to. |
Beta Was this translation helpful? Give feedback.
-
It seems not as simple as we thought println('0.5:${typeof(0.5).name}') >v run test.v
0.5:float literal |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The following example is very simple, essentially f32 + f64, but the type of result is very different, why? I'm confused about this, I'm not sure if this is a bug or intentional design, in short, I hope it can be designed to be easier to understand and uniform rules.
Beta Was this translation helpful? Give feedback.
All reactions