In scheme I can do this:
#;> (/ 1 3)
1/3
#;> (exact->inexact (/ 1 3))
0.3333333333333333
This is called an "exact division".
I was playing with BigDecimal
in Java and figured out that you can use its .divide()
function to make exact divisions, but this function throws an ArithmeticException
if the division is not exact. You can use other similar functions to specify how you want to round, but if I just don't want to round (equivalent in Scheme exact->inexact
function).
Is that possible using pure Java? Or maybe a library?