Comments (2)
I think it is the correct behavior.
Let's display both the decimal and binary values:
from gmpy2 import get_context, div_2exp, mpfr, next_below
get_context().precision = 2
get_context().emin = -2
get_context().emax = 3
get_context().subnormalize = False
a = div_2exp(mpfr(3), 4)
b = next_below(mpfr(0.25))
get_context().subnormalize = True
c = div_2exp(mpfr(3), 4)
d = next_below(mpfr(0.25))
a, a.__format__('b')
b, b.__format__('b')
c, c.__format__('b')
d, d.__format__('b')
The output is:
(mpfr('0.19',2), '1.1p-3')
(mpfr('0.19',2), '1.1p-3')
(mpfr('0.25',2), '1p-2')
(mpfr('0.12',2), '1p-3')
For 'a' and 'b', the binary output uses two bits ("1.1") but the exponent is -3 which is less than 'emin'. If the exponent is restricted to 'emin', the binary output for 'a' and 'b' would be '0.11p-2'. But this requires 3 bits ("0.11"). Subnormalize needs to round to 2 bits. div_2exp
follows the honors the rounding mode (round ties to even) so '0.11' is rounded to '1.0' or '1p-2'. 'next_below' just uses the next smaller so '0.11' becomes '0.10' or '1p-3'.
I think I got the analysis correct. But the subtleties floating point representations never cease to surprise me.
from gmpy.
I am closing this issue as @casevh gave an accurate analysis of what is going on -- there does not seem to be a bug here.
from gmpy.
Related Issues (20)
- bit_count() not found HOT 3
- Build failure on CPython 3.13 (dev)
- test failures with mpfr 4.2.1 (change in MPFR formatted functions) HOT 31
- New version? 🤔 HOT 15
- 2.1.5: test suite fails with errors `invalid option: '+SKIP_MPC_LESS_THAN_110'` HOT 9
- 2.1.5: *.h and *.pxd files are installed HOT 5
- Is the `is_strong_bpsw_prp` code correct? HOT 2
- Assessment of the difficulty in porting CPU architecture for the gmpy
- Description of `is_euler_prp` HOT 1
- mpz object missing to_bytes() method HOT 4
- complex conjugate crash HOT 2
- Linux wheels in the latest release (2.2.0a1) are broken HOT 10
- What is the paper that `is_extra_strong_lucas_prp` is referring to? HOT 4
- About the case where `k=0` is input to `lucasu_mod` and `lucasv_mod` HOT 2
- gmpy-2.1.5 fails to compile with python-3.12 HOT 10
- cython C-API is broken in published wheels (and in the build_wheels.yml CI workflow) HOT 9
- Pip install build fails, can't find mpc.h HOT 6
- Deprecate local_context()? HOT 18
- Impending release of gmpy2 2.2.0a2 HOT 10
- Issue with large factorial HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmpy.