Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's only true for integers.

For scientific applications you'd typically want floating points and Python's floats are just regular ieee-754 doubles (or whatever "double" meant to the compiler used to compile that python interpreter).



The disadvantage with floats is you can't do accurate computations due to having an inexact representation. Python has the same issues with floats.

For example: I do a lot of work with financial software and also some basic applied cryptography. And the essential rule is to never ever use floats. Where 'decimals' are needed you want them to be simulated using integers. Python has a module called decimal which I think helps mitigate some of these issues.

I've written some code to work with accurate, large precision numbers in Python and C before. Mostly the annoying part with this is having data types for the numbers that correspond well to database fields (like uint64) or are portable (in C its easiest if you can get a u128 but this type is very compiler-specific so some hacking may be needed.)

It's fun to work on code like this but definitely needs to be precise and have good test coverage. Writing your own math libraries that are going to be used for such important operations is hair-raising stuff.


Python also has a fixed point arithmetic in its std library: https://docs.python.org/3/library/decimal.html




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: