github.com/aykevl/tinygo@v0.5.0/testdata/float.go (about)

     1  package main
     2  
     3  func main() {
     4  	// sanity
     5  	println(3.14159265358979323846)
     6  
     7  	// float64
     8  	f64 := float64(2) / float64(3)
     9  	println(f64)
    10  	println(f64 + 1.0)
    11  	println(f64 - 1.0)
    12  	println(f64 * 2.0)
    13  	println(f64 / 2.0)
    14  
    15  	// float32
    16  	f32 := float32(2) / float32(3)
    17  	println(f32)
    18  	println(f32 + 1.0)
    19  	println(f32 - 1.0)
    20  	println(f32 * 2.0)
    21  	println(f32 / 2.0)
    22  
    23  	// casting
    24  	println(float32(f64))
    25  	println(float64(f32))
    26  
    27  	// float -> int
    28  	var f1 float32 = 3.3
    29  	var f2 float32 = 5.7
    30  	var f3 float32 = -2.3
    31  	var f4 float32 = -11.8
    32  	println(int32(f1), int32(f2), int32(f3), int32(f4))
    33  
    34  	// int -> float
    35  	var i1 int32 = 53
    36  	var i2 int32 = -8
    37  	var i3 uint32 = 20
    38  	println(float32(i1), float32(i2), float32(i3))
    39  
    40  	// complex64
    41  	c64 := complex(f32, 1.2)
    42  	println(c64)
    43  	println(real(c64))
    44  	println(imag(c64))
    45  
    46  	// complex128
    47  	c128 := complex(f64, -2.0)
    48  	println(c128)
    49  	println(real(c128))
    50  	println(imag(c128))
    51  
    52  	// untyped complex
    53  	println(2 + 1i)
    54  	println(complex(2, -2))
    55  
    56  	// cast complex
    57  	println(complex64(c128))
    58  	println(complex128(c64))
    59  }