3 ms·
> Incidentally, bc -l gives the right result, no matter how small you set scale. There's an easy explanation here: bc has it's own arbitrary precision number l
by shakna 7y ago
> Incidentally, bc -l gives the right result, no matter how small you set scale.
There's an easy explanation here: bc has it's own arbitrary precision number library embedded in it, so it doesn't make use of floats, doubles or even quads at all.
The number library is surprisingly readable [1] for such a complex topic, and doesn't use complex types at all, relying on ints and chars and pointers inside the struct it uses to store the numbers.
It's been wrapper up for a couple languages, I stumbled over it with a Lua wrapper [0]. Useful when you want better precision than you currently have, but don't want to drag in something like GMP and are okay with minor edge cases sometimes appearing.
[0] https://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/#lbc https://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/#lbc
[1] src/number.c & src/number.h from https://www.gnu.org/software/bc/ https://www.gnu.org/software/bc/