mattn / mattn/go-sqlite3

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

Open
#1,241 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
9.2k
Forks
1.2k
Avg merge
19m
Merged PRs (30d)
4

Description

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)
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the sample Go program and its sqlite_math_functions build tag, then compare select sin(8.9) through go-sqlite3 with the sqlite3 CLI on x86/musl and x86_64. Done means identifying the platform-specific cause and making the driver return the same correct value as SQLite on the affected target.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sqlite
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.