github.com/goplus/llgo@v0.8.3/cl/_testrt/cast/in.go (about) 1 package main 2 3 //"github.com/goplus/llgo/internal/runtime/c" 4 5 func main() { 6 cvt64to8(0, 0) 7 cvt64to8(127, 127) 8 cvt64to8(128, -128) 9 cvt64to8(-128, -128) 10 cvt64to8(-129, 127) 11 cvt64to8(256, 0) 12 13 cvt64to8U(0, 0) 14 cvt64to8U(255, 255) 15 cvt64to8U(256, 0) 16 cvt64to8U(257, 1) 17 cvt64to8U(-1, 255) 18 19 cvt32Fto8(0.1, 0) 20 cvt32Fto8(127.1, 127) 21 cvt32Fto8(128.1, -128) 22 cvt32Fto8(-128.1, -128) 23 cvt32Fto8(-129.1, 127) 24 cvt32Fto8(256.1, 0) 25 26 cvt32Fto8U(0, 0) 27 cvt32Fto8U(255, 255) 28 cvt32Fto8U(256, 0) 29 cvt32Fto8U(257, 1) 30 cvt32Fto8U(-1, 255) 31 32 // MaxInt32 = 1<<31 - 1 // 2147483647 33 // MinInt32 = -1 << 31 // -2147483648 34 cvt32Fto32(0, 0) 35 cvt32Fto32(1.5, 1) 36 cvt32Fto32(1147483647.1, 1147483648) 37 cvt32Fto32(2147483647.1, -2147483648) 38 cvt32Fto32(4147483647.1, -2147483648) 39 cvt32Fto32(-2147483648.1, -2147483648) 40 cvt32Fto32(-2147482648.1, -2147482624) 41 42 // MaxUint32 = 1<<32 - 1 // 4294967295 43 cvt32Fto32U(0, 0) 44 cvt32Fto32U(1.5, 1) 45 cvt32Fto32U(4294967295.1, 0) 46 cvt32Fto32U(5294967295.1, 1000000000) 47 cvt32Fto32U(-4294967295.1, 0) 48 cvt32Fto32U(-1294967295.1, 3000000000) 49 cvt32Fto32U(-1.1, 4294967295) 50 51 // MaxFloat32 = 0x1p127 * (1 + (1 - 0x1p-23)) // 3.40282346638528859811704183484516925440e+38 52 // SmallestNonzeroFloat32 = 0x1p-126 * 0x1p-23 // 1.401298464324817070923729583289916131280e-45 53 // MaxFloat64 = 0x1p1023 * (1 + (1 - 0x1p-52)) // 1.79769313486231570814527423731704356798070e+308 54 // SmallestNonzeroFloat64 = 0x1p-1022 * 0x1p-52 // 4.9406564584124654417656879286822137236505980e-324 55 56 cvt32Fto64F(0, 0) 57 cvt32Fto64F(1.5, 1.5) 58 cvt32Fto64F(1e10, 1e10) 59 cvt32Fto64F(-1e10, -1e10) 60 61 cvt64Fto32F(0, 0) 62 cvt64Fto32F(1.5, 1.5) 63 cvt64Fto32F(1e10, 1e10) 64 cvt64Fto32F(-1e10, -1e10) 65 66 // MaxInt64 = 1<<63 - 1 // 9223372036854775807 67 // MinInt64 = -1 << 63 // -9223372036854775808 68 cvt64to64F(0, 0) 69 cvt64to64F(1e10, 1e10) 70 cvt64to64F(9223372036854775807, 9223372036854775807) 71 cvt64to64F(-9223372036854775807, -9223372036854775807) 72 73 // MaxUint64 = 1<<64 - 1 // 18446744073709551615 74 cvt64Uto64F(0, 0) 75 cvt64Uto64F(1e10, 1e10) 76 cvt64Uto64F(9223372036854775807, 9223372036854775807) 77 cvt64Uto64F(18446744073709551615, 18446744073709551615) 78 79 cvt32to64(0, 0) 80 cvt32to64(2147483647, 2147483647) 81 82 cvtUinptr(1024, 1024) 83 } 84 85 func cvtUinptr(a int32, b uintptr) { 86 if uintptr(a) != b { 87 panic("error") 88 } 89 if int32(b) != a { 90 panic("error") 91 } 92 } 93 94 func cvt32to64(a int32, b int64) { 95 if int64(a) != b { 96 panic("error") 97 } 98 } 99 100 func cvt64to64F(a int64, b float64) { 101 if float64(a) != b { 102 panic("error") 103 } 104 } 105 106 func cvt64Uto64F(a uint64, b float64) { 107 if float64(a) != b { 108 panic("error") 109 } 110 } 111 112 func cvt64Fto32F(a float64, b float32) { 113 if float32(a) != b { 114 panic("error") 115 } 116 } 117 118 func cvt32Fto64F(a float32, b float64) { 119 if float64(a) != b { 120 panic("error") 121 } 122 } 123 124 func cvt32Fto32(a float32, b int32) { 125 if int32(a) != b { 126 panic("error") 127 } 128 } 129 130 func cvt32Fto32U(a float32, b uint32) { 131 if uint32(a) != b { 132 panic("error") 133 } 134 } 135 136 func cvt32Fto8(a float32, b int8) { 137 if int8(a) != b { 138 panic("error") 139 } 140 } 141 142 func cvt32Fto8U(a float32, b uint8) { 143 if uint8(a) != b { 144 panic("error") 145 } 146 } 147 148 func cvt64to8(a int64, b int8) { 149 if int8(a) != b { 150 panic("error") 151 } 152 } 153 154 func cvt64to8U(a int, b uint8) { 155 if uint8(a) != b { 156 panic("error") 157 } 158 }