Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Number/Maths Abstraction
    text
    copied!<p>I'm currently in the process of writing an application that has quite a number of mathematically calculations in it. In some situations, these calculations need to be done quickly and we can deal with a small amount of precision loss to get the maths done as fast as possible. On the other hand, sometimes we require that the calculations be done very precisely (and there are use cases for in between, where we would implement our own way of doing multiplication/division/addition/subtraction/power etc that is more precise that float * float (or double * double, I am aware that float is a bad choice), but faster than BigDecimal.multiply(BigDecimal)... or even something like apfloat rather than BigDecimal).</p> <p>Are there any existing libraries that allow an abstraction of such number formats, so that different ways of doing the maths are abstracted away, or do I have to create my own?</p> <p>I've started coding up something, which seems to be working <em>okay</em>, but it would be far better to have a nicely tested library rather than reinventing the wheel I think.</p> <p><strong>EDITED to clarify the situation with content from a comment below:</strong></p> <p>The problem is that BigDecimal is significantly slower than double * double etc. We need to be able to switch between precision and speed. The reasoning behind this is that we need to be able to run fast tests for debugging and cross checks with real world data (which does not need to be perfectly accurate), but the final simulation (which will often take days to weeks: unacceptable for debugging) will require high precision. Thus the need to be able to switch at will.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload