github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/compiler/testdata/float.go (about)

     1  package main
     2  
     3  // Test converting floats to ints.
     4  
     5  func f32tou32(v float32) uint32 {
     6  	return uint32(v)
     7  }
     8  
     9  func maxu32f() float32 {
    10  	return float32(^uint32(0))
    11  }
    12  
    13  func maxu32tof32() uint32 {
    14  	f := float32(^uint32(0))
    15  	return uint32(f)
    16  }
    17  
    18  func inftoi32() (uint32, uint32, int32, int32) {
    19  	inf := 1.0
    20  	inf /= 0.0
    21  
    22  	return uint32(inf), uint32(-inf), int32(inf), int32(-inf)
    23  }
    24  
    25  func u32tof32tou32(v uint32) uint32 {
    26  	return uint32(float32(v))
    27  }
    28  
    29  func f32tou32tof32(v float32) float32 {
    30  	return float32(uint32(v))
    31  }
    32  
    33  func f32tou8(v float32) uint8 {
    34  	return uint8(v)
    35  }
    36  
    37  func f32toi8(v float32) int8 {
    38  	return int8(v)
    39  }