General Algorithm for Primitive Calculation?


RE: I had the idea of rounding twice...
#8
(2016-08-12, 19:48)Travis Cobbs Wrote: I'm not positive, but the "correct" solution might be your original round4f, with one minor change. Instead of constructing a BigDecimal with just the double value (for arbitrary precision), construct it with the double value and a MathContext.DECIMAL64 as a second argument. Based on the documentation, this should make BigDecimal use IEEE 754 rounding rules, which I would expect to match the C# rounding.

Side note: I'm pretty sure your solution can trigger wrong rounding in other cases. Say, for example, that your calculated value is 0.5036499999999911 instead of 0.5036499999999999. You're going to round up to 0.5037 in that case, while 0.5036 would be the correct result. Also, it seems that you could avoid the whole string thing by rounding the BigDecimal to 8 places, and then rounding that rounded BigDecimal to 4 places.

Thanks!
I tried a few things and finally released the PrimGen2 clone with LDPartEditor 0.8.22.
At the beginning, I thought it would be quite simple to generate some LDraw primitives...
...it turns out to be another lecture in numerics instead :)
Reply
« Next Oldest | Next Newest »



Messages In This Thread
RE: I had the idea of rounding twice... - by Nils Schmidt - 2016-08-20, 10:05

Forum Jump:


Users browsing this thread: 1 Guest(s)