numeric - Numerical Accuracy: to scale or not? -


i working on n-body gravitational simulator takes input , produces output in metric mks units. involves dealing large numbers (like solar masses expressed in kilograms, semimajor axes of planetary orbits expressed in meters, , timescales of years expressed in seconds), multiplied small numbers (notably, gravitational constant, 6.67384e-11 in mks units), , occasional small number getting added or subtracted large number (mainly when summing pairwise accelerations), gets me concerned effects of rounding errors.

i've taken step of replacing masses m gm (premultiplying gravitational constant), reduces total number of multiplies, , makes mass numbers smaller, , seems have had positive effect on both efficiency , accuracy, judged how simulator conserves energy.

i wondering, however: potentially worth trying internal re-scaling different units further minimize floating point errors? , if so, kind of range (for double-precision floats) should trying numbers centered on maximum accuracy?

in general if want precise results in physical based rendering don't want use floats or doubles since have massive rounding problems , introduce errors in simulation.

if need or want stick floats/double should rescale around zero. reason floating point representations have higher "density" of values around point , tend have fewer on min/max sides. image example google

i suggest change values integer based number variables. erases rounding errors (over/underflow can still happen!) , speeds calculation process order of magnitude because normal cpus work faster integer operations. in case of gpu basically same thats story own...

but before take such effort further improve accuracy advise arbitrary precision number library. may come performance loss should way easier , yield better results rescaling of values.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -