cot(0)/coth(0) return Infinity while SQLite's own division returns NULL
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Read the cot/coth wrappers in src/main/ext/extension-functions.c and see where the result is pushed with sqlite3_result_double(). Change them so a zero denominator or non-finite result becomes sqlite3_result_null() instead. Verify by running the JDBC snippet in the issue against a rebuilt extension: cot(0) and coth(0) should print null, matching 1.0/tan(0) and 1.0/tanh(0).
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Java
- Stars
- 3.3k
- Forks
- 676
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 18
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from xerial/sqlite-jdbc
-
triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
xerial/sqlite-jdbc#1514 ·
Maintainers usually reply within 1 day
-
triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
xerial/sqlite-jdbc#1513 ·
Maintainers usually reply within 1 day
-
triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
xerial/sqlite-jdbc#1512 ·
Maintainers usually reply within 1 day
-
SIGSEGV (exit 134) in bundled `rightstr()` when the length argument is a large negative numberPossibly taken @sarthakdev143-lite claimed this 1 day ago. Openhelp wanted impacts:JNI
Difficulty 4/5 1-2 days Newbie friendliness 38/100
xerial/sqlite-jdbc#1508 ·
Maintainers usually reply within 1 day
-
triage
Difficulty 4/5 3-5 days Newbie friendliness 48/100
xerial/sqlite-jdbc#1483 ·
Maintainers usually reply within 1 day
All issues in xerial/sqlite-jdbc
Similar issues
-
Area/Configuration Type/Improvement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ballerina-platform/static-code-analysis-tool#217 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
eclipse-dirigible/dirigible#8636 · 1 comment ·
Maintainers usually reply within 1 day
-
bug severity-medium XS
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
nikolas-charalambidis/facepalm-maven-plugin#291 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
OakLoaf/PluginUpdater#264 ·
Maintainers usually reply within 1 day
-
[Bug]: withStartupTimeout() changes the startup timeout of all containers that use the default wait strategyPossibly taken @aymenjamaaoui claimed this today. Opentype/bug
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
testcontainers/testcontainers-java#12171 ·
Maintainers usually reply within 1 day