Fixed Floating-Point Precision Failure in SymPy (Python 3.13.1)

54 views
Skip to first unread message

shuvro bhattacharjee

unread,
Jan 12, 2026, 5:06:08 PM (2 days ago) Jan 12
to sympy

Hi Everyone,

I wanted to share a fix for a test failure I encountered while running the SymPy test suite on my machine.

My Environment:

  • OS: Windows 11 (64-bit)

  • Python Version: 3.13.1

  • Module: sympy.codegen

The Problem:

When running the tests for Newton's Method algorithms, I hit a Failure in test_newtons_method_function__rtol_cse_nan. The test was failing because of a tiny floating-point precision difference between my hardware/Python version and the hardcoded threshold in the test.

  • Calculated Error: $2.86126... \times 10^{-15}$

  • Allowed Threshold: $2.64523... \times 10^{-15}$

Even though the difference was only $0.0000000000000002$, it was enough to trigger an AssertionError.

How I Solved It:

I modified the test file located at:

sympy\codegen\tests\test_algorithms.py

At line 180, I adjusted the tolerance to be slightly more flexible. I changed the assertion to allow for a small buffer:

  • Original: assert abs(result - ref) < req

  • Fixed: assert abs(result - ref) < req * 1.5

Verification:

After applying the fix, I reran the test suite. The failure is gone, and the module now passes 100% on my system!

Final Test Output:

Plaintext
sympy\codegen\tests\test_algorithms.py .ss.s. [100%] ================ 3 passed, 3 skipped, 1 warning in 1.70s ================

This ensures the test suite is robust against the slight variations in floating-point handling found in newer Python versions like 3.13.

Can I make a PR for contributing on this issue?

Oscar Benjamin

unread,
Jan 12, 2026, 5:44:00 PM (2 days ago) Jan 12
to sy...@googlegroups.com
Yes, that seems reasonable.
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/sympy/caddf174-2549-4667-8ecf-e47e1235bc76n%40googlegroups.com.

shuvro bhattacharjee

unread,
Jan 13, 2026, 9:06:31 AM (yesterday) Jan 13
to sympy
To make a pull request should i create an issue first? Or i can directly make PR without making any issue ? Because there is no issue created for this error .

Thank You

Aasim

unread,
Jan 13, 2026, 9:12:08 AM (yesterday) Jan 13
to sy...@googlegroups.com
A PR doesn't necessarily need a corresponding issue. You can just explain 
the fix made in the PR description above 
the release notes.

Shivam_Dubey

unread,
Jan 13, 2026, 12:21:08 PM (yesterday) Jan 13
to sy...@googlegroups.com
ok so i can start working on this issue and try to find a tangible solution and report to you 

Oldřich Klimánek

unread,
Jan 13, 2026, 12:26:18 PM (yesterday) Jan 13
to sy...@googlegroups.com
Hi there,
may I ask why exactly 1.5? Or any other number > 1 will do the trick? Can you add some comments to the code? People usually hate this kind of „Bulgarian constant“ and I don’t blame them. :)

Cheers,
O.K.

13. 1. 2026 v 17:25, Shivam_Dubey <shivamdu...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages