3 ms·
If you use Haskell, then I'd recommend just using ghci over bc because you can't do floating point stuff in bc: 1/3 0 Whereas ghci, or your language's
by ancarda 7y ago
If you use Haskell, then I'd recommend just using ghci over bc because you can't do floating point stuff in bc:
1/3
0
Whereas ghci, or your language's REPL, will likely do better:
> 1/3
0.3333333333333333
- clappski 7y agoThat's because bc is fixed precision: % bc bc 1.07.1 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. scale=10 1/3 .3333333333
- encode 7y agoLaunch bc using the -l or --mathlib option to get 20 decimals of precision and load some basic math functions. I have this as an alias in my .bashrc, so I don't need to do this every time I launch the program.
- enriquto 7y agoyou can use pari-gp for your floating point needs inside unix. It's an extremely beautiful calculator language (for rational, floating point and polynomials). Also octave and julia, if you are mostly interested in matrices, but they take quite a few miliseconds to start and are not as useful inside shell loops.
- RBerenguel 7y agoYou can set up bc to any scale by adding scale=INTEGER for some reasonable INTEGER, say, 6, to your ~/.bc file (you need to also export BC_ENV_ARGS=~/.bc), or alias bc to bc -l). After having gp-pari fail after a brew upgrade I started using bc instead and have been relatively happy so far (although I miss isprime and factors which I used sparingly)
- faho 7y agoDo note that setting scale breaks modulo tho.