runtime: PrintFloat

This commit is contained in:
visualfc
2024-05-20 22:27:33 +08:00
parent 59b7d5a9f4
commit 5baa1aaa2a
4 changed files with 9 additions and 5 deletions

View File

@@ -25,7 +25,7 @@ func main() {
data = append(data, "def"...) data = append(data, "def"...)
println(data) println(data)
var i any = 100 var i any = 100
println(true, 100, -100, uint(255), int32(-100), 100.5, i, &i, uintptr(unsafe.Pointer(&i))) println(true, 0, 100, -100, uint(255), int32(-100), 0.0, 100.5, i, &i, uintptr(unsafe.Pointer(&i)))
var dst [3]byte var dst [3]byte
n := copy(dst[:], data) n := copy(dst[:], data)
println(n, dst[0], dst[1], dst[2]) println(n, dst[0], dst[1], dst[2])

View File

@@ -223,6 +223,8 @@ _llgo_0:
%96 = ptrtoint ptr %92 to i64 %96 = ptrtoint ptr %92 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 true) call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 true)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 0)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 100) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 100)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 -100) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 -100)
@@ -231,6 +233,8 @@ _llgo_0:
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 -100) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 -100)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double 0.000000e+00)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double 1.005000e+02) call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double 1.005000e+02)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/internal/runtime.PrintIface"(%"github.com/goplus/llgo/internal/runtime.iface" %95) call void @"github.com/goplus/llgo/internal/runtime.PrintIface"(%"github.com/goplus/llgo/internal/runtime.iface" %95)

Binary file not shown.

View File

@@ -23,19 +23,19 @@ func PrintBool(v bool) {
} }
func PrintFloat(v float64) { func PrintFloat(v float64) {
switch { // TODO(xsw): does c.Fprintf support these special cases? switch {
case v != v: case v != v:
c.Fprintf(c.Stderr, c.Str("NaN")) c.Fprintf(c.Stderr, c.Str("NaN"))
return return
case v+v == v: case v+v == v && v != 0:
if v > 0 { if v > 0 {
c.Fprintf(c.Stderr, c.Str("+Inf")) c.Fprintf(c.Stderr, c.Str("+Inf"))
} else if v < 0 { } else {
c.Fprintf(c.Stderr, c.Str("-Inf")) c.Fprintf(c.Stderr, c.Str("-Inf"))
} }
return return
} }
c.Fprintf(c.Stderr, c.Str("%g"), v) c.Fprintf(c.Stderr, c.Str("%e"), v)
} }
// func PrintComplex(c complex128) { // func PrintComplex(c complex128) {