From 7e1d19d57318d40ec13f270641b1a42f09345013 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sun, 4 Oct 2026 14:56:36 +0800 Subject: [PATCH] TestLongDouble --- c/c_test.go | 31 +++++++++++++++++ c/{ldobule_float64.go => ldouble_float64.go} | 2 +- c/ldouble_x87.go | 35 ++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 c/c_test.go rename c/{ldobule_float64.go => ldouble_float64.go} (95%) create mode 100644 c/ldouble_x87.go diff --git a/c/c_test.go b/c/c_test.go new file mode 100644 index 0000000..9840805 --- /dev/null +++ b/c/c_test.go @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package c_test + +import ( + "testing" + "unsafe" + + "github.com/goplus/lib/c" +) + +func TestLongDouble(t *testing.T) { + var ld c.LongDouble + if c.LongDoubleSize != unsafe.Sizeof(ld) { + t.Fatalf("unexpected LongDoubleSize: %d", c.LongDoubleSize) + } +} diff --git a/c/ldobule_float64.go b/c/ldouble_float64.go similarity index 95% rename from c/ldobule_float64.go rename to c/ldouble_float64.go index 903fe47..a62cbb1 100644 --- a/c/ldobule_float64.go +++ b/c/ldouble_float64.go @@ -1,7 +1,7 @@ //go:build (windows && !(mingw && (amd64 || 386))) || (darwin && arm64) || arm || mips || mipsle || ((ppc64 || ppc64le) && !linux) /* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. + * Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/c/ldouble_x87.go b/c/ldouble_x87.go new file mode 100644 index 0000000..c66d449 --- /dev/null +++ b/c/ldouble_x87.go @@ -0,0 +1,35 @@ +//go:build amd64 && (!windows || mingw) + +/* + * Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package c + +// LongDouble is the x87 80-bit extended precision format, stored in 16 bytes +// (10 significant bytes + 6 bytes padding). Applies to x86-64 on +// Linux/macOS/BSD and MinGW on Windows. +// +// The C ABI requires 16-byte alignment, which Go cannot express (Go caps +// alignment at 8); the zero-size field below gives 8-byte alignment at most. +// When embedding LongDouble in a mirrored C struct, add explicit padding so +// the field offset is a multiple of 16. +type LongDouble struct { + _ [0]uint64 + Data [16]byte +} + +// LongDoubleSize is sizeof(long double) in bytes on this target. +const LongDoubleSize = 16