Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions c/c_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 1 addition & 1 deletion c/ldobule_float64.go → c/ldouble_float64.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
35 changes: 35 additions & 0 deletions c/ldouble_x87.go
Original file line number Diff line number Diff line change
@@ -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
Loading