Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RealDigits should truncate digits without rounding #1137

Open
davidar opened this issue Oct 20, 2024 · 0 comments
Open

RealDigits should truncate digits without rounding #1137

davidar opened this issue Oct 20, 2024 · 0 comments

Comments

@davidar
Copy link
Collaborator

davidar commented Oct 20, 2024

Description

Currently, RealDigits uses N[] to evaluate to the necessary precision before extracting digits. However, this involves rounding to the nearest digit, which differs from the behaviour of RealDigits in WMA.

In some cases you can work around it by evaluating to a greater precision than needed, but this doesn't work in general when there's e.g. an arbitrarily long series of 9s. It seems like the best solution would be to be able to supply a rounding mode to the numerical evaluation routines? MPMath has some support for setting rounding modes on individual operations, but there doesn't appear to be a global interface for it like there is for precision, and I'm not familiar enough with how this is used in mathics to trace every call that would need to changed to support this. I'm sure there's other cases I'm overlooking too.

How to Reproduce / Output Given

Mathics 7.0.1dev0
on CPython 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0]
using SymPy 1.12, mpmath 1.3.0, numpy 1.26.4, cython Not installed

Copyright (C) 2011-2024 The Mathics3 Team.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
See the documentation for the full license.

Quit by evaluating Quit[] or by pressing CONTROL-D.

In[1]:= RealDigits[1 - 10^-100, 10, 5]
Out[1]= {{1, 0, 0, 0, 0}, 1}

In[2]:= RealDigits[Sqrt[104], 10, 1, -1]
Out[2]= {{2}, 0}

Expected behavior

Wolfram Language 14.1.0 Engine for Microsoft Windows (64-bit)
Copyright 1988-2024 Wolfram Research, Inc.

In[1]:= RealDigits[1 - 10^-100, 10, 5]

Out[1]= {{9, 9, 9, 9, 9}, 0}

In[2]:= RealDigits[Sqrt[104], 10, 1, -1]

Out[2]= {{1}, 0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant