discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

for statement doesn't do all the steps sometimes

RR
rl.ward rl.ward
Wed, Dec 21, 2016 3:07 AM

Surely using "counting" numbers eg integers to count loops, and
separately, use floating point ("measurement numbers") if required for
the solution, is a good idea?  However to mash these two processes
together, and then not expect inconsistencies is a forlorn hope?  I
don't believe the language should have to create a "nanny state" (not a
bad pun there), where misuse of these concepts are auto-magically
corrected. Caveat Emptor! or maybe a User Beware warning, seeing the
software is not purchased, could be spelt out in the support
information.  I suspect for many people openSCAD maybe the first time
some users have crafted scripts and not aware of the linititations of
representing our real world of infinite ranges of precision, with a
finite binary state machine.
Rob
------ Original Message ------
From: "Tim V. Shaporev" tim.shaporev@auriga.ru
To: discuss@lists.openscad.org
Sent: Wednesday, 21 Dec, 2016 At 2:50 AM
Subject: Re: [OpenSCAD] for statement doesn't do all the steps sometimes

So do not implement it as floating point: use rational representation.

On 12/20/2016 6:49 PM, Jean-Paul Louis wrote:

Tim,

Your assumption is not true.
Openscad CANNOT represent exactly 0.1 in binary floating point.
That’s why there are so many issues with rounding errors at
boundaries.

Just my $0.02,
Jean-Paul
N1JPL

On Dec 20, 2016, at 3:55 AM, Shaporev, Timur tim@auriga.com wrote:

Consider different approach:
OpenSCAD is able to represent decimals exactly: 0.2 as 2/10 (or 1/5)
etc.
This would require to change compiler of course.

Just my $0.02
Tim


From: Discuss [discuss-bounces@lists.openscad.org] on behalf of doug
moen [doug@moens.org]
Sent: 20 December 2016 01:02
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] for statement doesn't do all the steps
sometimes

The fix I implemented is based on the Haskell implementation of
floating point numeric ranges. That was the best reference
implementation that I could find at the time.

The first:step:last syntax is taken from Matlab. I found Matlab
source code for the colon operator, it's here:
https://gist.github.com/Juanlu001/7383894

This fixes the bug, and it is more backward compatible with
OpenSCAD than the Haskell implementation.

On 17 December 2016 at 02:59, Johan Jonker
<johangjonker@zonnet.nlmailto:johangjonker@zonnet.nl> wrote:
I found a remarkable difference  in version 2016.10.4 using for
statement
with increments smaller than 1. Sometimes the end value is not
reached.

for (a7=[ 6.8:1/5:7.8]) echo(A7=a7);
for (a=[ 7.2:1/5:8.2]) echo(A=a);

Output is
ECHO: A7 = 6.8
ECHO: A7 = 7
ECHO: A7 = 7.2
ECHO: A7 = 7.4
ECHO: A7 = 7.6
ECHO: A = 7.2
ECHO: A = 7.4
ECHO: A = 7.6
ECHO: A = 7.8
ECHO: A = 8
ECHO: A = 8.2

--
View this message in context:
http://forum.openscad.org/for-statement-doesn-t-do-all-the-steps-sometimes-tp19591.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.orgmailto:Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Rob Ward

+613 5156 5388  or  +61419 470 734

30 Hillcrest Way, Lake Tyers Beach,3909

http://www.laketyersbeach.net.au

Surely using "counting" numbers eg integers to count loops, and separately, use floating point ("measurement numbers") if required for the solution, is a good idea? However to mash these two processes together, and then not expect inconsistencies is a forlorn hope? I don't believe the language should have to create a "nanny state" (not a bad pun there), where misuse of these concepts are auto-magically corrected. Caveat Emptor! or maybe a User Beware warning, seeing the software is not purchased, could be spelt out in the support information. I suspect for many people openSCAD maybe the first time some users have crafted scripts and not aware of the linititations of representing our real world of infinite ranges of precision, with a finite binary state machine. Rob ------ Original Message ------ From: "Tim V. Shaporev" <tim.shaporev@auriga.ru> To: discuss@lists.openscad.org Sent: Wednesday, 21 Dec, 2016 At 2:50 AM Subject: Re: [OpenSCAD] for statement doesn't do all the steps sometimes So do not implement it as floating point: use rational representation. On 12/20/2016 6:49 PM, Jean-Paul Louis wrote: > Tim, > > Your assumption is not true. > Openscad CANNOT represent exactly 0.1 in binary floating point. > That’s why there are so many issues with rounding errors at > boundaries. > > Just my $0.02, > Jean-Paul > N1JPL > > > >> On Dec 20, 2016, at 3:55 AM, Shaporev, Timur <tim@auriga.com> wrote: >> >> Consider different approach: >> OpenSCAD is able to represent decimals exactly: 0.2 as 2/10 (or 1/5) >> etc. >> This would require to change compiler of course. >> >> Just my $0.02 >> Tim >> ________________________________________ >> From: Discuss [discuss-bounces@lists.openscad.org] on behalf of doug >> moen [doug@moens.org] >> Sent: 20 December 2016 01:02 >> To: OpenSCAD general discussion >> Subject: Re: [OpenSCAD] for statement doesn't do all the steps >> sometimes >> >> The fix I implemented is based on the Haskell implementation of >> floating point numeric ranges. That was the best reference >> implementation that I could find at the time. >> >> The first:step:last syntax is taken from Matlab. I found Matlab >> source code for the colon operator, it's here: >> https://gist.github.com/Juanlu001/7383894 >> >> This fixes the bug, *and* it is more backward compatible with >> OpenSCAD than the Haskell implementation. >> >> On 17 December 2016 at 02:59, Johan Jonker >> <johangjonker@zonnet.nl<mailto:johangjonker@zonnet.nl>> wrote: >> I found a remarkable difference in version 2016.10.4 using for >> statement >> with increments smaller than 1. Sometimes the end value is not >> reached. >> >> >> for (a7=[ 6.8:1/5:7.8]) echo(A7=a7); >> for (a=[ 7.2:1/5:8.2]) echo(A=a); >> >> Output is >> ECHO: A7 = 6.8 >> ECHO: A7 = 7 >> ECHO: A7 = 7.2 >> ECHO: A7 = 7.4 >> ECHO: A7 = 7.6 >> ECHO: A = 7.2 >> ECHO: A = 7.4 >> ECHO: A = 7.6 >> ECHO: A = 7.8 >> ECHO: A = 8 >> ECHO: A = 8.2 >> >> >> >> -- >> View this message in context: >> http://forum.openscad.org/for-statement-doesn-t-do-all-the-steps-sometimes-tp19591.html >> Sent from the OpenSCAD mailing list archive at Nabble.com. >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org<mailto:Discuss@lists.openscad.org> >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > _______________________________________________ OpenSCAD mailing list Discuss@lists.openscad.org http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org Rob Ward +613 5156 5388 or +61419 470 734 30 Hillcrest Way, Lake Tyers Beach,3909 http://www.laketyersbeach.net.au
JD
Jerry Davis
Wed, Dec 21, 2016 3:21 AM

I personally think that:

  1. use integer only numbers for the start, step, stop.
  2. then do whatever calculation inside the loop to do what you want.

And document the heck out of it, and why.

This way people who are new to OpenScad can turn to the documentation
to see how it works.

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Openscad developer

The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov

On Tue, Dec 20, 2016 at 8:07 PM, rl.ward rl.ward rl.ward@bigpond.com
wrote:

Surely using "counting" numbers eg integers to count loops, and
separately, use floating point ("measurement numbers") if required for the
solution, is a good idea?  However to mash these two processes together,
and then not expect inconsistencies is a forlorn hope?  I don't believe the
language should have to create a "nanny state" (not a bad pun there), where
misuse of these concepts are auto-magically corrected. Caveat Emptor! or
maybe a User Beware warning, seeing the software is not purchased, could be
spelt out in the support information.  I suspect for many people openSCAD
maybe the first time some users have crafted scripts and not aware of the
linititations of representing our real world of infinite ranges of
precision, with a finite binary state machine.
Rob

------ Original Message ------
From: "Tim V. Shaporev" tim.shaporev@auriga.ru
To: discuss@lists.openscad.org
Sent: Wednesday, 21 Dec, 2016 At 2:50 AM
Subject: Re: [OpenSCAD] for statement doesn't do all the steps sometimes

So do not implement it as floating point: use rational representation.

On 12/20/2016 6:49 PM, Jean-Paul Louis wrote:

Tim,

Your assumption is not true.
Openscad CANNOT represent exactly 0.1 in binary floating point.
That’s why there are so many issues with rounding errors at boundaries.

Just my $0.02,
Jean-Paul
N1JPL

On Dec 20, 2016, at 3:55 AM, Shaporev, Timur tim@auriga.com wrote:

Consider different approach:
OpenSCAD is able to represent decimals exactly: 0.2 as 2/10 (or 1/5) etc.
This would require to change compiler of course.

Just my $0.02
Tim


From: Discuss [discuss-bounces@lists.openscad.org] on behalf of doug
moen [doug@moens.org]
Sent: 20 December 2016 01:02
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] for statement doesn't do all the steps sometimes

The fix I implemented is based on the Haskell implementation of floating
point numeric ranges. That was the best reference implementation that I
could find at the time.

The first:step:last syntax is taken from Matlab. I found Matlab source
code for the colon operator, it's here:
https://gist.github.com/Juanlu001/7383894

This fixes the bug, and it is more backward compatible with OpenSCAD
than the Haskell implementation.

On 17 December 2016 at 02:59, Johan Jonker <johangjonker@zonnet.nl
mailto:johangjonker@zonnet.nl> wrote:
I found a remarkable difference  in version 2016.10.4 using for statement
with increments smaller than 1. Sometimes the end value is not reached.

for (a7=[ 6.8:1/5:7.8]) echo(A7=a7);
for (a=[ 7.2:1/5:8.2]) echo(A=a);

Output is
ECHO: A7 = 6.8
ECHO: A7 = 7
ECHO: A7 = 7.2
ECHO: A7 = 7.4
ECHO: A7 = 7.6
ECHO: A = 7.2
ECHO: A = 7.4
ECHO: A = 7.6
ECHO: A = 7.8
ECHO: A = 8
ECHO: A = 8.2

--
View this message in context: http://forum.openscad.org/for-
statement-doesn-t-do-all-the-steps-sometimes-tp19591.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.orgmailto:Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I personally think that: 1. use integer only numbers for the start, step, stop. 2. then do whatever calculation inside the loop to do what you want. And document the heck out of it, and why. This way people who are new to OpenScad can turn to the documentation to see how it works. -- Extra Ham Operator: K7AZJ Registered Linux User: 275424 Raspberry Pi and Openscad developer *The most exciting phrase to hear in science - the one that heralds new discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov On Tue, Dec 20, 2016 at 8:07 PM, rl.ward rl.ward <rl.ward@bigpond.com> wrote: > Surely using "counting" numbers eg integers to count loops, and > separately, use floating point ("measurement numbers") if required for the > solution, is a good idea? However to mash these two processes together, > and then not expect inconsistencies is a forlorn hope? I don't believe the > language should have to create a "nanny state" (not a bad pun there), where > misuse of these concepts are auto-magically corrected. Caveat Emptor! or > maybe a User Beware warning, seeing the software is not purchased, could be > spelt out in the support information. I suspect for many people openSCAD > maybe the first time some users have crafted scripts and not aware of the > linititations of representing our real world of infinite ranges of > precision, with a finite binary state machine. > Rob > > ------ Original Message ------ > From: "Tim V. Shaporev" <tim.shaporev@auriga.ru> > To: discuss@lists.openscad.org > Sent: Wednesday, 21 Dec, 2016 At 2:50 AM > Subject: Re: [OpenSCAD] for statement doesn't do all the steps sometimes > > So do not implement it as floating point: use rational representation. > > On 12/20/2016 6:49 PM, Jean-Paul Louis wrote: > >> Tim, >> >> Your assumption is not true. >> Openscad CANNOT represent exactly 0.1 in binary floating point. >> That’s why there are so many issues with rounding errors at boundaries. >> >> Just my $0.02, >> Jean-Paul >> N1JPL >> >> >> >> On Dec 20, 2016, at 3:55 AM, Shaporev, Timur <tim@auriga.com> wrote: >>> >>> Consider different approach: >>> OpenSCAD is able to represent decimals exactly: 0.2 as 2/10 (or 1/5) etc. >>> This would require to change compiler of course. >>> >>> Just my $0.02 >>> Tim >>> ________________________________________ >>> From: Discuss [discuss-bounces@lists.openscad.org] on behalf of doug >>> moen [doug@moens.org] >>> Sent: 20 December 2016 01:02 >>> To: OpenSCAD general discussion >>> Subject: Re: [OpenSCAD] for statement doesn't do all the steps sometimes >>> >>> The fix I implemented is based on the Haskell implementation of floating >>> point numeric ranges. That was the best reference implementation that I >>> could find at the time. >>> >>> The first:step:last syntax is taken from Matlab. I found Matlab source >>> code for the colon operator, it's here: >>> https://gist.github.com/Juanlu001/7383894 >>> >>> This fixes the bug, *and* it is more backward compatible with OpenSCAD >>> than the Haskell implementation. >>> >>> On 17 December 2016 at 02:59, Johan Jonker <johangjonker@zonnet.nl >>> <mailto:johangjonker@zonnet.nl>> wrote: >>> I found a remarkable difference in version 2016.10.4 using for statement >>> with increments smaller than 1. Sometimes the end value is not reached. >>> >>> >>> for (a7=[ 6.8:1/5:7.8]) echo(A7=a7); >>> for (a=[ 7.2:1/5:8.2]) echo(A=a); >>> >>> Output is >>> ECHO: A7 = 6.8 >>> ECHO: A7 = 7 >>> ECHO: A7 = 7.2 >>> ECHO: A7 = 7.4 >>> ECHO: A7 = 7.6 >>> ECHO: A = 7.2 >>> ECHO: A = 7.4 >>> ECHO: A = 7.6 >>> ECHO: A = 7.8 >>> ECHO: A = 8 >>> ECHO: A = 8.2 >>> >>> >>> >>> -- >>> View this message in context: http://forum.openscad.org/for- >>> statement-doesn-t-do-all-the-steps-sometimes-tp19591.html >>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org<mailto:Discuss@lists.openscad.org> >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >>> >>> >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > > > Rob Ward > > +613 5156 5388 or +61419 470 734 > > 30 Hillcrest Way, Lake Tyers Beach,3909 > > http://www.laketyersbeach.net.au > > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >