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
"The expression T(v) converts the value v to the type T."
The above statement wrongly interprets the expression.
should'nt it be meant more as if
var a float64 = 5.3;
var b int32=int32(a);
now here the value of "a" does not change to int32 instead the assigned variable b gets the change in datatype value of a.
The text was updated successfully, but these errors were encountered:
"The expression T(v) converts the value v to the type T."
is already correct as it is in my view.
What I found confusing is the code example, which doesn't appear to relate to this concept at all.
package main
import (
"fmt"
"math"
)
func main() {
var x, y int = 3, 4
var f float64 = math.Sqrt(float64(x*x + y*y))
var z uint = uint(f)
fmt.Println(x, y, z)
}
Instead, I would suggest a much more trivial code alternative demonstrates the effect more clearly by converting from float64 to int (and the loss of precision that causes)
package main
import (
"fmt"
)
func main() {
var x1, x2 float64 = 1.123, 2.345
var y1, y2 int = int(x1), int(x2) // Key Concept
fmt.Println(x1, x2)
fmt.Println(y1, y2)
}
// returns:
// 1.123 2.345
// 1 2
Context: https://go.dev/tour/basics/13
"The expression T(v) converts the value v to the type T."
The above statement wrongly interprets the expression.
should'nt it be meant more as if
var a float64 = 5.3;
var b int32=int32(a);
now here the value of "a" does not change to int32 instead the assigned variable b gets the change in datatype value of a.
The text was updated successfully, but these errors were encountered: