cot(0)/coth(0) return Infinity while SQLite's own division returns NULL

Aperta Adatta ai principianti
#1,515 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, java, sqlite
Ambito
databases

Direzione di ricerca

Leggi i wrapper cot/coth in src/main/ext/extension-functions.c e vedi dove il risultato viene inserito con sqlite3_result_double(). Modificali in modo che un denominatore zero o un risultato non finito diventi invece sqlite3_result_null(). Verifica eseguendo lo snippet JDBC nell'issue contro un'estensione ricompilata: cot(0) e coth(0) dovrebbero stampare null, come 1.0/tan(0) e 1.0/tanh(0).

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

triage

Describe the bug

cot(0) and coth(0) return IEEE Infinity, while the equivalent expression written with SQLite's own operators (1.0/tan(0)) returns NULL, because SQLite defines division by zero as NULL. The same mathematical operation therefore yields two different results inside one database connection, depending on whether it is spelled as a function call or as an expression.

To Reproduce

import java.sql.*;

public class Repro {
  public static void main(String[] args) throws Exception {
    try (Connection c = DriverManager.getConnection("jdbc:sqlite::memory:");
         Statement s = c.createStatement()) {
      String[] q = {
        "SELECT cot(0), 1.0/tan(0)",
        "SELECT coth(0), 1.0/tanh(0)"
      };
      for (String x : q) {
        try (ResultSet r = s.executeQuery(x)) {
          r.next();
          System.out.println(x + "  => " + r.getObject(1) + " | " + r.getObject(2));
        }
      }
    }
  }
}

Expected behavior

cot(0) and coth(0) should return NULL, matching SQLite's division-by-zero semantics (1.0/tan(0) is already NULL), instead of exposing an infinity value that SQLite itself never produces from arithmetic.

Logs

SELECT cot(0), 1.0/tan(0)    => Infinity | null
SELECT coth(0), 1.0/tanh(0)  => Infinity | null

Environment (please complete the following information):

  • OS: macOS 15.6.1
  • CPU architecture: arm64
  • sqlite-jdbc version: 3.54.1.0

Additional context

Root cause in src/main/ext/extension-functions.c: cot/coth are plain C wrappers over 1.0/tan(x) and 1.0/tanh(x); C division yields Inf (or raises a domain error caught by errno), and the value is pushed straight back with sqlite3_result_double(). SQLite never sees a division operator, so its own "divide by zero is NULL" rule is bypassed.

Suggested fix: explicitly convert a non-finite result to NULL, or a zero denominator to NULL, so the function agrees with the arithmetic semantics of the database it runs in.

Found by PST while testing built-in functions locally.

Lingua principale
Java
Stelle
3.3k
Fork
676
Merge medio
1g 15h
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di xerial/sqlite-jdbc

Tutte le issue di xerial/sqlite-jdbc

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.