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

Support float/double types #16

Open
disconnect3d opened this issue Mar 23, 2019 · 1 comment
Open

Support float/double types #16

disconnect3d opened this issue Mar 23, 2019 · 1 comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@disconnect3d
Copy link
Owner

Even when cint stays for integers, it would be cool to add support for float/double types.

@disconnect3d disconnect3d added help wanted Extra attention is needed good first issue Good for newcomers labels Mar 23, 2019
@disconnect3d
Copy link
Owner Author

Some nice things we want here:

  1. Ability to create the float/double from its binary representation (e.g. F32.from_le(0x1234) should create the float from its little-endian representation, .from_be(..) from big endian) etc.
  2. Methods to convert to int value and a string binary representation
In [12]: bin(ctypes.c_float(float('NaN')))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[12], line 1
----> 1 bin(ctypes.c_float(float('NaN')))

TypeError: 'c_float' object cannot be interpreted as an integer
  1. Support for special values (NaN, -0, -inf, +inf), it should probably work out of the box:
In [10]: ctypes.c_float(float('NaN'))
Out[10]: c_float(nan)
  1. Support for various math operators, e.g., this should just work:
In [11]: ctypes.c_float(float('NaN')) + 2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[11], line 1
----> 1 ctypes.c_float(float('NaN')) + 2

TypeError: unsupported operand type(s) for +: 'c_float' and 'int'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant