1

In the most upvoted answer to the question Double precision floating values in Python? it is mentioned that we can use np.float128, if we need precision more than standard float. But I couldn't find a way to do this.

Then, in the most upvoted answer to how to declare variable type, C style in python, use of typing is suggested.

However, when I tried to use typing to set the datatype as float for a integer type value, Python still used an int data type.

n : float=10000
print(type(n))

But still, the result is :

<class 'int'>

So, How can I define np.float128 type variable in python?

2
  • 1
    Variables don't have types in Python; values do, and 10000 is perfectly representable as an int. Commented Aug 6, 2020 at 18:13
  • 1
    variables aren't typed in python. Python is a dynamically typed language. Type hints are hints to people reading the source code, or for use by third-party static type checkers. The Python runtime itself ignores them, basically. You want to create a np.float128 object, but are you sure that's what you want? Why not decimal.Decimal, which supports arbitrary precision? Commented Aug 6, 2020 at 18:13

1 Answer 1

2

Have you tried the following?

from numpy import float128

n=float128(10000)

print(type(n))

Print:

<class 'numpy.float128'>

Bear in mind that there are some issues using numpy.float128 on Windows 64-bit (see numpy.float128 doesn't exist in windows, but is called from OpenGL). I have tested this code in an online Python editor.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.