# Rounding Errors

12 messages
Open this post in threaded view
|

## Rounding Errors

Open this post in threaded view
|

## Re: Rounding Errors

 What you describe is the Anglo-American way of rounding numbers. It makes sense if you do not count in decimals, but in half-inches, quarter-inches, etc. In Europe, where we rather work with factors of 10 instead of factors of 2, absolute values of .5 and higher are rounded up and the rest down. I think that computationally, this is a more fair way to do things, as the outcome follows from the algorithm instead of the other way around. Some programming languages have an extra parameter to let the programmer decide what method to use in rounding. I can imagine that for OpenSCAD, this would be an enhancement, since you cannot round a variable, look at the outcome, and then change that same variable.
Open this post in threaded view
|

## Re: Rounding Errors

 In reply to this post by wolf On 2017-07-14 03:47, wolf wrote: > In the OpenSCAD manual, rounding is described as > > *round* > The "round" operator returns the greatest or least integer part, > respectively, if the numeric input is positive or negative. > > This rounding practice is not in line with  IEEE 754 I believe the OpenSCAD built-in round function exposes the C/C++ function of the same name. http://www.cplusplus.com/reference/cmath/round/"Returns the integral value that is nearest to x, with halfway cases rounded away from zero." Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Rounding Errors

Open this post in threaded view
|

## Re: Rounding Errors

Open this post in threaded view
|

## Re: Rounding Errors

Open this post in threaded view
|

## Re: Rounding Errors

 In reply to this post by doug.moen To report back what I learnt: Software rounding: The GCC library libc provides rounding modes for all IEEE754-2008 rounding functions, not just the four doug.moen listed. There is the page on rounding modes, and there is a page on rounding functions. Round-to-even is available from function rint, via setting a rounding mode, and also from function roundeven. Hardware rounding: Intel hardware , page 106, table 4.8 rounds to even as default. It does not support OpenSCAD-type rounding at all. The reason for that is that round-to-even average rounding error is only half that of OpenSCAD-type rounding, and Intel ties to provide accurate results whenever the number format permits it. With regard to doug.moen's drange function, here are the results:  using AnyShape=(let (Step=360/Resolution) [ for (k=[0 : Step : 180] ) [ for( i=[Step :Step : 360] ) Sphere(i,k) ] ] );    using AnyShape=(let (Step=360/Resolution) [ for (k=drange(0,Step,180)) [ for( i=drange(Step,Step,360) ) Sphere(i,k) ] ] );    using AnyShape=(let (I_Step=360/Resolution, K_Step=180/round(Resolution/2)) [ for (k=[0 : 1 : round(Resolution/2)] ) [ for( i=[1 : 1 : Resolution] ) Sphere(i*I_Step,k*K_Step) ] ] );   All three will approximate well sphere at higher resolutions. Which one does it at the low resolution? On nophead's code I have one thing to say: it works. Why? All I can say is that nophead's reasoning is most likely wrong, as all rotations will have to rely on either fsin, fcos or fsincos assembler functions to access the hardware, and all three are based upon radians, and not degrees. But since a programmer or his/her compiler may choose between fsin and fcos on the one hand and fsincos on the other, without the ability to access the implementation at assembly language level, it's hard to say what happens. wolf
Open this post in threaded view
|

## Re: Rounding Errors

Open this post in threaded view
|

## Re: Rounding Errors

 Administrator tp3 wrote Fixing that would remove the need for the user space function. So fix it? Admin - email* me if you need anything, or if I've done something stupid... * click on my MichaelAtOz label, there is a link to email me. Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Open this post in threaded view
|

## Re: Rounding Errors

 On 07/26/2017 12:36 AM, MichaelAtOz wrote: > tp3 wrote >> Fixing that would remove the need for the user space function. > > So fix it? > That needs both time and motivation. I have none of the first, comments like that don't help with the latter... ciao,   Torsten. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Torsten