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

underflow / saturation of unsigned list not working #73

Open
AndrzejKowalski9917 opened this issue Oct 26, 2022 · 3 comments
Open

underflow / saturation of unsigned list not working #73

AndrzejKowalski9917 opened this issue Oct 26, 2022 · 3 comments
Labels
OS:Windows Issue when running in Windows
Milestone

Comments

@AndrzejKowalski9917
Copy link

AndrzejKowalski9917 commented Oct 26, 2022

Description

When subtracting a larger unsigned number from a smaller one the result is correctly 0.0. If both values are part of a list, the result is wrong, if an underflow occurs (seems to be set to the upper limit, instead of the lower one).

Minimal example:

from fxpmath import Fxp

# single unsigned value does work
a = Fxp(10, False, 14, 3)
b = Fxp(15, False, 14, 3)
c = a - b
print(c)  # 0.0 --> correct
c.info(verbose=3)

# unsigned list does not work
d = Fxp([10, 21], False, 14, 3)
e = Fxp([15, 15], False, 14, 3)
f = d - e
print(f)  # [4095.875 6.0] --> 4095.875 is the upper limit
f.info(verbose=3)

c.info(verbose=3) delivers the following output:

dtype = fxp-u15/3
Value = 0.0
underflow = True
inaccuracy = True
Signed = False
Word bits = 15
Fract bits = 3
Int bits = 12
Val data type = None
Upper = 4095.875
Lower = 0.0
Precision = 0.125
Overflow = saturate
Rounding = trunc
Shifting = expand

f.info(verbose=3) this output:

dtype = fxp-u15/3
Value = [4095.875 6.0]
overflow = True
inaccuracy = True
Signed = False
Word bits = 15
Fract bits = 3
Int bits = 12
Val data type = None
Upper = 4095.875
Lower = 0.0
Precision = 0.125
Overflow = saturate
Rounding = trunc
Shifting = expand

Version infos

  • OS: Windows 10 21H2 (19044.2130)
  • python: 3.7.6 (miniconda), 3.10.8 (mingw64)
  • fxpmath: 0.4.8
@francof2a
Copy link
Owner

Hello @AndrzejKowalski9917

I tested your example in a fresh conda environment with python 3.7.6 (conda), fxpmath 0.4.8 (from anaconda) and I couldn't reproduce de error.
I also tested in a conda env with python 3.8.13 and fxpmath installed from Pip, and it's also working well.
Both runs were performed in linux, so I can not tell about relationship with Windows OS yet.

What version of numpy are you using?
Could you run again your example in a fresh conda env?

@AndrzejKowalski9917
Copy link
Author

AndrzejKowalski9917 commented Nov 10, 2022

Hi @francof2a ,

thank you for your answer. I tried now in Linux (Arch) with

  • python 3.10.8
  • numpy 1.23.4
  • fxpmath 0.4.8

and also were not able to reproduce the error. In Windows I also tried python 3.10.0, installed via the installer from python.org, fxpmath and numpy installed via pip (same versions as on Linux). Here the error occurs.
I can try a fresh conda env in Windows tomorrow at work.

@AndrzejKowalski9917
Copy link
Author

AndrzejKowalski9917 commented Nov 11, 2022

Hello @francof2a,

I just tried at work again (Windows 10) with a clean virtualenv (conda env does not work here for reasons unknown).
Python is still version 3.7.6 and only the following packages are installed:

(test_env) D:\tmp\py>pip list
Package Version
---------- -------
fxpmath 0.4.8
numpy 1.21.6
pip 22.3.1
setuptools 65.5.1
wheel 0.38.4

The error persists. So it seems to be an error specific to the Windows OS.

EDIT:
I just noticed, while c.info(verbose=3) prints underflow = True, that on Windows f.info(verbose=3) prints overflow = True, which is also wrong.

@francof2a francof2a added the OS:Windows Issue when running in Windows label Dec 21, 2023
@francof2a francof2a added this to the v0.4.10 milestone Feb 8, 2024
francof2a added a commit that referenced this issue Feb 10, 2024
This fix #73 #76 and #85 in windows OS using numpy 32 bit integer type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS:Windows Issue when running in Windows
Projects
None yet
Development

No branches or pull requests

2 participants