go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Inconsistent behavior of sin() math function on x86 (musl / alpine)

Open mil opened this issue 9 months ago • 0 comments

It seems there is a bug where on x86 (tested on musl/alpine 3.19) I'm getting incorrect values for the sin() function.

Given a sample program which just runs select sin(8.9):

Results on x86 (incorrect):

-2.1634211956023357

Result on x86_64 (correct):

0.5010208564578846

Running within the sqlite3 CLI the same select sin(8.9) on x86 returns the correct 0.5010208564578846; so I believe this is a bug in go-sqlite3 or a binding. I'm not sure if this just effects alpine/musl x86 or additionally glibc x86.


Sample test program:

// Run via go run -tags=sqlite_math_functions foo.go
package main

import (
	"database/sql"
	"fmt"
	"log"
	_ "github.com/mattn/go-sqlite3"
)

func main() {
	db, err := sql.Open("sqlite3", ":memory:")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()
	rows, err := db.Query("select sin(8.9)")
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()
	var result float64
	for rows.Next() {
		if err := rows.Scan(&result); err != nil {
			log.Fatal(err)
		}
	}
	fmt.Println("Result:", result)
}

mil avatar May 10 '24 12:05 mil