Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C float and double not implemented #3193

Closed
Mossaka opened this issue Sep 23, 2022 · 5 comments
Closed

C float and double not implemented #3193

Mossaka opened this issue Sep 23, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@Mossaka
Copy link

Mossaka commented Sep 23, 2022

How to reproduce

package main

// #include <stdlib.h>
import "C"
import "fmt"

func FromCFloat(x C.float) float32 {
	return float32(x)
}

func main() {
	res := FromCFloat(C.float(1.0))
	fmt.Println(res)
}
(base) ➜  tinygo-float-repro go run main.go
# command-line-arguments
ld: warning: -no_pie is deprecated when targeting new OS versions
1
(base) ➜  tinygo-float-repro tinygo run main.go
# command-line-arguments
main.go:7:19: undeclared name: C.float
main.go:12:20: undeclared name: C.float
@dgryski
Copy link
Member

dgryski commented Sep 23, 2022

Probably some missing aliases here: https:/tinygo-org/tinygo/blob/release/cgo/cgo.go

@aykevl
Copy link
Member

aykevl commented Sep 23, 2022

Indeed, those aliases are simply missing and are trivial to add.

However, you don't generally need them in TinyGo because C float is the same as Go float32 and C double is the same as Go float64.

@dgryski
Copy link
Member

dgryski commented Sep 23, 2022

Hmm...

diff --git a/cgo/cgo.go b/cgo/cgo.go
index dfdd223e..af9fa9f7 100644
--- a/cgo/cgo.go
+++ b/cgo/cgo.go
@@ -86,6 +86,8 @@ var cgoAliases = map[string]string{
        "C.uint32_t":  "uint32",
        "C.uint64_t":  "uint64",
        "C.uintptr_t": "uintptr",
+       "C.float":     "float32",
+       "C.double":    "float64",
 }

Doesn't seem to work.

~/go/src/github.com/dgryski/bug $ tinygo run bug.go
# command-line-arguments
bug.go:7:19: undeclared name: C.float
bug.go:12:20: undeclared name: C.float

Is there something else that needs to know about them?

@deadprogram deadprogram added the enhancement New feature or request label Sep 26, 2022
@aykevl
Copy link
Member

aykevl commented Sep 29, 2022

Here is a fix: #3210. Adding them was a little bit less trivial than I expected.

@deadprogram
Copy link
Member

0.27.0 has now been released, so closing. Thank you!

@deadprogram deadprogram removed the next-release Will be part of next release label Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants