From f6ad4dcef54c5ce997a4bad5a6d86de229015700 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 16 Apr 2024 21:25:22 +0200 Subject: Adding upstream version 1.22.1. Signed-off-by: Daniel Baumann --- test/ken/convert.go | 432 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 432 insertions(+) create mode 100644 test/ken/convert.go (limited to 'test/ken/convert.go') diff --git a/test/ken/convert.go b/test/ken/convert.go new file mode 100644 index 0000000..33acbd8 --- /dev/null +++ b/test/ken/convert.go @@ -0,0 +1,432 @@ +// run + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test, near-exhaustive, of converting numbers between types. +// No complex numbers though. + +package main + +var i8 int8; +var u8 uint8; +var i16 int16; +var u16 uint16; +var i32 int32; +var u32 uint32; +var i64 int64; +var u64 uint64; +var f32 float32; +var f64 float64; + +type big float64 + +type t struct { + from, to int + val big +} + +const ( + ti8 = iota+1 + tu8 + ti16 + tu16 + ti32 + tu32 + ti64 + tu64 + tf32 + tf64 +) + +var x = []t{ + + /* value good in all types (10) */ + { ti8, ti8, 10 }, { ti8, tu8, 10 }, { ti8, ti16, 10 }, { ti8, tu16, 10 }, + { ti8, ti32, 10 }, { ti8, tu32, 10 }, { ti8, ti64, 10 }, { ti8, tu64, 10 }, + { ti8, tf32, 10 }, { ti8, tf64, 10 }, + + { tu8, ti8, 10 }, { tu8, tu8, 10 }, { tu8, ti16, 10 }, { tu8, tu16, 10 }, + { tu8, ti32, 10 }, { tu8, tu32, 10 }, { tu8, ti64, 10 }, { tu8, tu64, 10 }, + { tu8, tf32, 10 }, { tu8, tf64, 10 }, + + { ti16, ti8, 10 }, { ti16, tu8, 10 }, { ti16, ti16, 10 }, { ti16, tu16, 10 }, + { ti16, ti32, 10 }, { ti16, tu32, 10 }, { ti16, ti64, 10 }, { ti16, tu64, 10 }, + { ti16, tf32, 10 }, { ti16, tf64, 10 }, + + { tu16, ti8, 10 }, { tu16, tu8, 10 }, { tu16, ti16, 10 }, { tu16, tu16, 10 }, + { tu16, ti32, 10 }, { tu16, tu32, 10 }, { tu16, ti64, 10 }, { tu16, tu64, 10 }, + { tu16, tf32, 10 }, { tu16, tf64, 10 }, + + { ti32, ti8, 10 }, { ti32, tu8, 10 }, { ti32, ti16, 10 }, { ti32, tu16, 10 }, + { ti32, ti32, 10 }, { ti32, tu32, 10 }, { ti32, ti64, 10 }, { ti32, tu64, 10 }, + { ti32, tf32, 10 }, { ti32, tf64, 10 }, + + { tu32, ti8, 10 }, { tu32, tu8, 10 }, { tu32, ti16, 10 }, { tu32, tu16, 10 }, + { tu32, ti32, 10 }, { tu32, tu32, 10 }, { tu32, ti64, 10 }, { tu32, tu64, 10 }, + { tu32, tf32, 10 }, { tu32, tf64, 10 }, + + { ti64, ti8, 10 }, { ti64, tu8, 10 }, { ti64, ti16, 10 }, { ti64, tu16, 10 }, + { ti64, ti32, 10 }, { ti64, tu32, 10 }, { ti64, ti64, 10 }, { ti64, tu64, 10 }, + { ti64, tf32, 10 }, { ti64, tf64, 10 }, + + { tu64, ti8, 10 }, { tu64, tu8, 10 }, { tu64, ti16, 10 }, { tu64, tu16, 10 }, + { tu64, ti32, 10 }, { tu64, tu32, 10 }, { tu64, ti64, 10 }, { tu64, tu64, 10 }, + { tu64, tf32, 10 }, { tu64, tf64, 10 }, + + { tf32, ti8, 10 }, { tf32, tu8, 10 }, { tf32, ti16, 10 }, { tf32, tu16, 10 }, + { tf32, ti32, 10 }, { tf32, tu32, 10 }, { tf32, ti64, 10 }, { tf32, tu64, 10 }, + { tf32, tf32, 10 }, { tf32, tf64, 10 }, + + { tf64, ti8, 10 }, { tf64, tu8, 10 }, { tf64, ti16, 10 }, { tf64, tu16, 10 }, + { tf64, ti32, 10 }, { tf64, tu32, 10 }, { tf64, ti64, 10 }, { tf64, tu64, 10 }, + { tf64, tf32, 10 }, { tf64, tf64, 10 }, + + /* value good in all signed types (-4) */ + { ti8, ti8, -4 }, { ti8, ti16, -4 }, + { ti8, ti32, -4 }, { ti8, ti64, -4 }, + { ti8, tf32, -4 }, { ti8, tf64, -4 }, + + { ti16, ti8, -4 }, { ti16, ti16, -4 }, + { ti16, ti32, -4 }, { ti16, ti64, -4 }, + { ti16, tf32, -4 }, + + { ti32, ti8, -4 }, { ti32, ti16, -4 }, + { ti32, ti32, -4 }, { ti32, ti64, -4 }, + { ti32, tf32, -4 }, { ti32, tf64, -4 }, + + { ti64, ti8, -4 }, { ti64, ti16, -4 }, + { ti64, ti32, -4 }, { ti64, ti64, -4 }, + { ti64, tf32, -4 }, + + { tf32, ti8, -4 }, { tf32, ti16, -4 }, + { tf32, ti32, -4 }, { tf32, ti64, -4 }, + { tf32, tf32, -4 }, + + { tf64, ti8, -4 }, { tf64, ti16, -4 }, + { tf64, ti32, -4 }, { tf64, ti64, -4 }, + { tf64, tf32, -4 }, { tf64, tf64, -4 }, + + /* value good in u8 and up (175) */ + { tu8, tu8, 175 }, { tu8, ti16, 175 }, { tu8, tu16, 175 }, + { tu8, ti32, 175 }, { tu8, tu32, 175 }, { tu8, ti64, 175 }, { tu8, tu64, 175 }, + { tu8, tf32, 175 }, { tu8, tf64, 175 }, + + { ti16, tu8, 175 }, { ti16, ti16, 175 }, { ti16, tu16, 175 }, + { ti16, ti32, 175 }, { ti16, tu32, 175 }, { ti16, ti64, 175 }, { ti16, tu64, 175 }, + { ti16, tf32, 175 }, { ti16, tf64, 175 }, + + { tu16, tu8, 175 }, { tu16, ti16, 175 }, { tu16, tu16, 175 }, + { tu16, ti32, 175 }, { tu16, tu32, 175 }, { tu16, ti64, 175 }, { tu16, tu64, 175 }, + { tu16, tf32, 175 }, { tu16, tf64, 175 }, + + { ti32, tu8, 175 }, { ti32, ti16, 175 }, { ti32, tu16, 175 }, + { ti32, ti32, 175 }, { ti32, tu32, 175 }, { ti32, ti64, 175 }, { ti32, tu64, 175 }, + { ti32, tf32, 175 }, { ti32, tf64, 175 }, + + { tu32, tu8, 175 }, { tu32, ti16, 175 }, { tu32, tu16, 175 }, + { tu32, ti32, 175 }, { tu32, tu32, 175 }, { tu32, ti64, 175 }, { tu32, tu64, 175 }, + { tu32, tf32, 175 }, { tu32, tf64, 175 }, + + { ti64, tu8, 175 }, { ti64, ti16, 175 }, { ti64, tu16, 175 }, + { ti64, ti32, 175 }, { ti64, tu32, 175 }, { ti64, ti64, 175 }, { ti64, tu64, 175 }, + { ti64, tf32, 175 }, { ti64, tf64, 175 }, + + { tu64, tu8, 175 }, { tu64, ti16, 175 }, { tu64, tu16, 175 }, + { tu64, ti32, 175 }, { tu64, tu32, 175 }, { tu64, ti64, 175 }, { tu64, tu64, 175 }, + { tu64, tf32, 175 }, { tu64, tf64, 175 }, + + { tf32, tu8, 175 }, { tf32, ti16, 175 }, { tf32, tu16, 175 }, + { tf32, ti32, 175 }, { tf32, tu32, 175 }, { tf32, ti64, 175 }, { tf32, tu64, 175 }, + { tf32, tf32, 175 }, { tf32, tf64, 175 }, + + { tf64, tu8, 175 }, { tf64, ti16, 175 }, { tf64, tu16, 175 }, + { tf64, ti32, 175 }, { tf64, tu32, 175 }, { tf64, ti64, 175 }, { tf64, tu64, 175 }, + { tf64, tf32, 175 }, { tf64, tf64, 175 }, + + /* value good in u16 and up (41259) */ + { tu16, tu16, 41259 }, + { tu16, ti32, 41259 }, { tu16, ti64, 41259 }, { tu16, tu64, 41259 }, + { tu16, tf32, 41259 }, { tu16, tf64, 41259 }, + + { ti32, tu16, 41259 }, + { ti32, ti32, 41259 }, { ti32, tu32, 41259 }, { ti32, ti64, 41259 }, { ti32, tu64, 41259 }, + { ti32, tf32, 41259 }, { ti32, tf64, 41259 }, + + { tu32, tu16, 41259 }, + { tu32, ti32, 41259 }, { tu32, tu32, 41259 }, { tu32, ti64, 41259 }, { tu32, tu64, 41259 }, + { tu32, tf32, 41259 }, { tu32, tf64, 41259 }, + + { ti64, tu16, 41259 }, + { ti64, ti32, 41259 }, { ti64, tu32, 41259 }, { ti64, ti64, 41259 }, { ti64, tu64, 41259 }, + { ti64, tf32, 41259 }, { ti64, tf64, 41259 }, + + { tu64, tu16, 41259 }, + { tu64, ti32, 41259 }, { tu64, tu32, 41259 }, { tu64, ti64, 41259 }, { tu64, tu64, 41259 }, + { tu64, tf32, 41259 }, { tu64, tf64, 41259 }, + + { tf32, tu16, 41259 }, + { tf32, ti32, 41259 }, { tf32, tu32, 41259 }, { tf32, ti64, 41259 }, { tf32, tu64, 41259 }, + { tf32, tf32, 41259 }, { tf32, tf64, 41259 }, + + { tf64, tu16, 41259 }, + { tf64, ti32, 41259 }, { tf64, tu32, 41259 }, { tf64, ti64, 41259 }, { tf64, tu64, 41259 }, + { tf64, tf32, 41259 }, { tf64, tf64, 41259 }, + + /* value good in u32 and up (3758096384) */ + { tu32, tu32, 3758096384 }, { tu32, ti64, 3758096384 }, { tu32, tu64, 3758096384 }, + { tu32, tf32, 3758096384 }, { tu32, tf64, 3758096384 }, + + { ti64, tu32, 3758096384 }, { ti64, ti64, 3758096384 }, { ti64, tu64, 3758096384 }, + { ti64, tf32, 3758096384 }, { ti64, tf64, 3758096384 }, + + { tu64, tu32, 3758096384 }, { tu64, ti64, 3758096384 }, { tu64, tu64, 3758096384 }, + { tu64, tf32, 3758096384 }, { tu64, tf64, 3758096384 }, + + { tf32, tu32, 3758096384 }, { tf32, ti64, 3758096384 }, { tf32, tu64, 3758096384 }, + { tf32, tf32, 3758096384 }, { tf32, tf64, 3758096384 }, + + { tf64, tu32, 3758096384 }, { tf64, ti64, 3758096384 }, { tf64, tu64, 3758096384 }, + { tf64, tf32, 3758096384 }, { tf64, tf64, 3758096384 }, + + /* value good in u64 and up (16717361816799281152) */ + { tu64, tu64, 16717361816799281152 }, + { tu64, tf32, 16717361816799281152 }, { tu64, tf64, 16717361816799281152 }, + + { tf32, tu64, 16717361816799281152 }, + { tf32, tf32, 16717361816799281152 }, { tf32, tf64, 16717361816799281152 }, + + { tf64, tu64, 16717361816799281152 }, + { tf64, tf32, 16717361816799281152 }, { tf64, tf64, 16717361816799281152 }, +} + +func main() { + for i:=0; i