Java BigDecimal trigonometric methods

ApFloat is a library which contains arbitrary-precision approximations of trigometric functions and non-integer powers both; however, it uses its own internal representations, rather than BigDecimal and BigInteger. I haven’t used it before, so I can’t vouch for its correctness or performance characteristics, but the api seems fairly complete.

C- Floating point precision

Binary floating point cannot represent the value 0.1 exactly, because its binary expansion does not have a finite number of digits (in exactly the same way that the decimal expansion of 1/7 does not). The binary expansion of 0.1 is 0.000110011001100110011001100… When truncated to IEEE-754 single precision, this is approximately 0.100000001490116119 in decimal. This means … Read more

Issue when scheduling tasks using clock() function

If I was to implement some timer mechanism in C++, I would probably be using the std::chrono namespace together with std::priority_queue. #include <functional> #include <queue> #include <chrono> #include <sys/time.h> // for `time_t` and `struct timeval` namespace events { struct event { typedef std::function<void()> callback_type; typedef std::chrono::time_point<std::chrono::system_clock> time_type; event(const callback_type &cb, const time_type &when) : callback_(cb), … Read more

Representing integers in doubles

An IEEE754 64-bit double can represent any 32-bit integer, simply because it has 53-odd(a) bits available for precision and the 32-bit integer only needs, well, 32 🙂 It would be plausible for a (non IEEE754 double precision) 64-bit floating point number to have less than 32 bits of precision. That would allow truly huge numbers … Read more