Skip to content

Internal numpy array incorrectly stores truncated values #31

@DanChianucci

Description

@DanChianucci

It looks like the internally stored np array doesn't always use the correct dtype.

From the example below you can see that depending on how the variable are initialized, certain operations don't work.

Given the fxp data type, I would have expected all internal arrays to be of uint64, especially since they are initialized from the same "constructor"

from fxpmath import Fxp,Config


t= Fxp(2**32,dtype="u32.32",shifting="trunc")
print(t.dtype , t.val.dtype ,  t )    # fxp-u64/32 int32 0.0


s  = t(0.125);
print(s.dtype , s.val.dtype ,  s )    # fxp-u64/32 int32 0.125


q  = t(0.125)<<3;
print(q.dtype , q.val.dtype ,  q )    # fxp-u64/32 int32 0.0


q2 = t(0.125)*2**3;
print(q2.dtype, q2.val.dtype,  q2)    # fxp-u64/32 int32 0.0


q3 = t(0.125*2**3);
print(q3.dtype, q3.val.dtype,  q3)    # fxp-u64/32 int64 1.0


# Looks like the above q3 statement upconverted 
# the backend type, and in doing so modified how 
# s is interpretted even though no changes are made 
# to s
print(s.dtype , s.val.dtype ,  s )    #  fxp-u64/32 int64 1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions