discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

for statement doesn't do all the steps sometimes

JJ
Johan Jonker
Sat, Dec 17, 2016 7:59 AM

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.

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.
JJ
Johan Jonker
Sat, Dec 17, 2016 8:03 AM

a workaround is:

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

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

a workaround is: for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7); for (a=[ 7.2:1/5:8.2]) echo(A=a); -- View this message in context: http://forum.openscad.org/for-statement-doesn-t-do-all-the-steps-sometimes-tp19591p19592.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Sat, Dec 17, 2016 11:07 AM

1/5 is a recurring fraction in binary so it is not surprising. I never use
floating point steps in a for loop. It is much better to use integer steps
and then scale down the loop index

On 17 December 2016 at 08:03, Johan Jonker johangjonker@zonnet.nl wrote:

a workaround is:

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

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


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

1/5 is a recurring fraction in binary so it is not surprising. I never use floating point steps in a for loop. It is much better to use integer steps and then scale down the loop index On 17 December 2016 at 08:03, Johan Jonker <johangjonker@zonnet.nl> wrote: > a workaround is: > > for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7); > for (a=[ 7.2:1/5:8.2]) echo(A=a); > > > > -- > View this message in context: http://forum.openscad.org/for- > statement-doesn-t-do-all-the-steps-sometimes-tp19591p19592.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
JD
Jerry Davis
Sat, Dec 17, 2016 12:58 PM

It is still that way in the latest snapshot.

I looked at the Documentation, and I consider this a bug.

The Documentation clearly has floating point values in the start, step,
end. And the definitions of start step and end, clearly state that it stops
when the next value would be greater. Clearly, not what this does.

You should put this in as a bug.

Jerry

--
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 Sat, Dec 17, 2016 at 4:07 AM, nop head nop.head@gmail.com wrote:

1/5 is a recurring fraction in binary so it is not surprising. I never use
floating point steps in a for loop. It is much better to use integer steps
and then scale down the loop index

On 17 December 2016 at 08:03, Johan Jonker johangjonker@zonnet.nl wrote:

a workaround is:

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

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


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

It is still that way in the latest snapshot. I looked at the Documentation, and I consider this a bug. The Documentation clearly has floating point values in the start, step, end. And the definitions of start step and end, clearly state that it stops when the next value would be greater. Clearly, not what this does. You should put this in as a bug. Jerry -- 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 Sat, Dec 17, 2016 at 4:07 AM, nop head <nop.head@gmail.com> wrote: > 1/5 is a recurring fraction in binary so it is not surprising. I never use > floating point steps in a for loop. It is much better to use integer steps > and then scale down the loop index > > On 17 December 2016 at 08:03, Johan Jonker <johangjonker@zonnet.nl> wrote: > >> a workaround is: >> >> for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7); >> for (a=[ 7.2:1/5:8.2]) echo(A=a); >> >> >> >> -- >> View this message in context: http://forum.openscad.org/for- >> statement-doesn-t-do-all-the-steps-sometimes-tp19591p19592.html >> Sent from the OpenSCAD mailing list archive at Nabble.com. >> >> _______________________________________________ >> 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 > >
NH
nop head
Sat, Dec 17, 2016 1:05 PM

Use this to see why it doesn't behave as expected:

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

ECHO: A7 = -1

ECHO: A7 = -0.8

ECHO: A7 = -0.6

ECHO: A7 = -0.4

ECHO: A7 = -0.2

ECHO: A7 = 8.88178e-016

ECHO: A = 0

ECHO: A = 0.2

ECHO: A = 0.4

ECHO: A = 0.6

ECHO: A = 0.8

ECHO: A = 1

As you can see repeatedly adding 0.2 slightly overshoots 7.8. This is
because they are both infinitely recurring binary fractions, not exact
decimal values.

On 17 December 2016 at 12:58, Jerry Davis jdawgaz@gmail.com wrote:

It is still that way in the latest snapshot.

I looked at the Documentation, and I consider this a bug.

The Documentation clearly has floating point values in the start, step,
end. And the definitions of start step and end, clearly state that it stops
when the next value would be greater. Clearly, not what this does.

You should put this in as a bug.

Jerry

--
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 Sat, Dec 17, 2016 at 4:07 AM, nop head nop.head@gmail.com wrote:

1/5 is a recurring fraction in binary so it is not surprising. I never
use floating point steps in a for loop. It is much better to use integer
steps and then scale down the loop index

On 17 December 2016 at 08:03, Johan Jonker johangjonker@zonnet.nl
wrote:

a workaround is:

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

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


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

Use this to see why it doesn't behave as expected: for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7 - 7.8); for (a=[ 7.2:1/5:8.2]) echo(A=a - 7.2); ECHO: A7 = -1 ECHO: A7 = -0.8 ECHO: A7 = -0.6 ECHO: A7 = -0.4 ECHO: A7 = -0.2 ECHO: A7 = 8.88178e-016 ECHO: A = 0 ECHO: A = 0.2 ECHO: A = 0.4 ECHO: A = 0.6 ECHO: A = 0.8 ECHO: A = 1 As you can see repeatedly adding 0.2 slightly overshoots 7.8. This is because they are both infinitely recurring binary fractions, not exact decimal values. On 17 December 2016 at 12:58, Jerry Davis <jdawgaz@gmail.com> wrote: > It is still that way in the latest snapshot. > > I looked at the Documentation, and I consider this a bug. > > The Documentation clearly has floating point values in the start, step, > end. And the definitions of start step and end, clearly state that it stops > when the next value would be greater. Clearly, not what this does. > > You should put this in as a bug. > > Jerry > > > > > -- > 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 Sat, Dec 17, 2016 at 4:07 AM, nop head <nop.head@gmail.com> wrote: > >> 1/5 is a recurring fraction in binary so it is not surprising. I never >> use floating point steps in a for loop. It is much better to use integer >> steps and then scale down the loop index >> >> On 17 December 2016 at 08:03, Johan Jonker <johangjonker@zonnet.nl> >> wrote: >> >>> a workaround is: >>> >>> for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7); >>> for (a=[ 7.2:1/5:8.2]) echo(A=a); >>> >>> >>> >>> -- >>> View this message in context: http://forum.openscad.org/for- >>> statement-doesn-t-do-all-the-steps-sometimes-tp19591p19592.html >>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> 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 > >
NH
nop head
Sat, Dec 17, 2016 1:07 PM

Sorry, typo

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

ECHO: A7 = -1

ECHO: A7 = -0.8

ECHO: A7 = -0.6

ECHO: A7 = -0.4

ECHO: A7 = -0.2

ECHO: A7 = 8.88178e-016

ECHO: A = -1

ECHO: A = -0.8

ECHO: A = -0.6

ECHO: A = -0.4

ECHO: A = -0.2

ECHO: A = 0

On 17 December 2016 at 13:05, nop head nop.head@gmail.com wrote:

Use this to see why it doesn't behave as expected:

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

ECHO: A7 = -1

ECHO: A7 = -0.8

ECHO: A7 = -0.6

ECHO: A7 = -0.4

ECHO: A7 = -0.2

ECHO: A7 = 8.88178e-016

ECHO: A = 0

ECHO: A = 0.2

ECHO: A = 0.4

ECHO: A = 0.6

ECHO: A = 0.8

ECHO: A = 1

As you can see repeatedly adding 0.2 slightly overshoots 7.8. This is
because they are both infinitely recurring binary fractions, not exact
decimal values.

On 17 December 2016 at 12:58, Jerry Davis jdawgaz@gmail.com wrote:

It is still that way in the latest snapshot.

I looked at the Documentation, and I consider this a bug.

The Documentation clearly has floating point values in the start, step,
end. And the definitions of start step and end, clearly state that it stops
when the next value would be greater. Clearly, not what this does.

You should put this in as a bug.

Jerry

--
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 Sat, Dec 17, 2016 at 4:07 AM, nop head nop.head@gmail.com wrote:

1/5 is a recurring fraction in binary so it is not surprising. I never
use floating point steps in a for loop. It is much better to use integer
steps and then scale down the loop index

On 17 December 2016 at 08:03, Johan Jonker johangjonker@zonnet.nl
wrote:

a workaround is:

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

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


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

Sorry, typo for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7 - 7.8); for (a=[ 7.2:1/5:8.2]) echo(A=a - 8.2); ECHO: A7 = -1 ECHO: A7 = -0.8 ECHO: A7 = -0.6 ECHO: A7 = -0.4 ECHO: A7 = -0.2 ECHO: A7 = 8.88178e-016 ECHO: A = -1 ECHO: A = -0.8 ECHO: A = -0.6 ECHO: A = -0.4 ECHO: A = -0.2 ECHO: A = 0 On 17 December 2016 at 13:05, nop head <nop.head@gmail.com> wrote: > Use this to see why it doesn't behave as expected: > > for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7 - 7.8); > for (a=[ 7.2:1/5:8.2]) echo(A=a - 7.2); > > ECHO: A7 = -1 > > ECHO: A7 = -0.8 > > ECHO: A7 = -0.6 > > ECHO: A7 = -0.4 > > ECHO: A7 = -0.2 > > ECHO: A7 = 8.88178e-016 > > ECHO: A = 0 > > ECHO: A = 0.2 > > ECHO: A = 0.4 > > ECHO: A = 0.6 > > ECHO: A = 0.8 > > ECHO: A = 1 > > > As you can see repeatedly adding 0.2 slightly overshoots 7.8. This is > because they are both infinitely recurring binary fractions, not exact > decimal values. > > > > On 17 December 2016 at 12:58, Jerry Davis <jdawgaz@gmail.com> wrote: > >> It is still that way in the latest snapshot. >> >> I looked at the Documentation, and I consider this a bug. >> >> The Documentation clearly has floating point values in the start, step, >> end. And the definitions of start step and end, clearly state that it stops >> when the next value would be greater. Clearly, not what this does. >> >> You should put this in as a bug. >> >> Jerry >> >> >> >> >> -- >> 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 Sat, Dec 17, 2016 at 4:07 AM, nop head <nop.head@gmail.com> wrote: >> >>> 1/5 is a recurring fraction in binary so it is not surprising. I never >>> use floating point steps in a for loop. It is much better to use integer >>> steps and then scale down the loop index >>> >>> On 17 December 2016 at 08:03, Johan Jonker <johangjonker@zonnet.nl> >>> wrote: >>> >>>> a workaround is: >>>> >>>> for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7); >>>> for (a=[ 7.2:1/5:8.2]) echo(A=a); >>>> >>>> >>>> >>>> -- >>>> View this message in context: http://forum.openscad.org/for- >>>> statement-doesn-t-do-all-the-steps-sometimes-tp19591p19592.html >>>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>>> >>>> _______________________________________________ >>>> 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 >> >> >
NH
nop head
Sat, Dec 17, 2016 1:09 PM

echo (6.8 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2 - 7.8);

ECHO: 8.88178e-016

On 17 December 2016 at 13:07, nop head nop.head@gmail.com wrote:

Sorry, typo

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

ECHO: A7 = -1

ECHO: A7 = -0.8

ECHO: A7 = -0.6

ECHO: A7 = -0.4

ECHO: A7 = -0.2

ECHO: A7 = 8.88178e-016

ECHO: A = -1

ECHO: A = -0.8

ECHO: A = -0.6

ECHO: A = -0.4

ECHO: A = -0.2

ECHO: A = 0

On 17 December 2016 at 13:05, nop head nop.head@gmail.com wrote:

Use this to see why it doesn't behave as expected:

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

ECHO: A7 = -1

ECHO: A7 = -0.8

ECHO: A7 = -0.6

ECHO: A7 = -0.4

ECHO: A7 = -0.2

ECHO: A7 = 8.88178e-016

ECHO: A = 0

ECHO: A = 0.2

ECHO: A = 0.4

ECHO: A = 0.6

ECHO: A = 0.8

ECHO: A = 1

As you can see repeatedly adding 0.2 slightly overshoots 7.8. This is
because they are both infinitely recurring binary fractions, not exact
decimal values.

On 17 December 2016 at 12:58, Jerry Davis jdawgaz@gmail.com wrote:

It is still that way in the latest snapshot.

I looked at the Documentation, and I consider this a bug.

The Documentation clearly has floating point values in the start, step,
end. And the definitions of start step and end, clearly state that it stops
when the next value would be greater. Clearly, not what this does.

You should put this in as a bug.

Jerry

--
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 Sat, Dec 17, 2016 at 4:07 AM, nop head nop.head@gmail.com wrote:

1/5 is a recurring fraction in binary so it is not surprising. I never
use floating point steps in a for loop. It is much better to use integer
steps and then scale down the loop index

On 17 December 2016 at 08:03, Johan Jonker johangjonker@zonnet.nl
wrote:

a workaround is:

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

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


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

echo (6.8 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2 - 7.8); ECHO: 8.88178e-016 On 17 December 2016 at 13:07, nop head <nop.head@gmail.com> wrote: > Sorry, typo > > for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7 - 7.8); > for (a=[ 7.2:1/5:8.2]) echo(A=a - 8.2); > > ECHO: A7 = -1 > > ECHO: A7 = -0.8 > > ECHO: A7 = -0.6 > > ECHO: A7 = -0.4 > > ECHO: A7 = -0.2 > > ECHO: A7 = 8.88178e-016 > > ECHO: A = -1 > > ECHO: A = -0.8 > > ECHO: A = -0.6 > > ECHO: A = -0.4 > > ECHO: A = -0.2 > > ECHO: A = 0 > > > > > > On 17 December 2016 at 13:05, nop head <nop.head@gmail.com> wrote: > >> Use this to see why it doesn't behave as expected: >> >> for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7 - 7.8); >> for (a=[ 7.2:1/5:8.2]) echo(A=a - 7.2); >> >> ECHO: A7 = -1 >> >> ECHO: A7 = -0.8 >> >> ECHO: A7 = -0.6 >> >> ECHO: A7 = -0.4 >> >> ECHO: A7 = -0.2 >> >> ECHO: A7 = 8.88178e-016 >> >> ECHO: A = 0 >> >> ECHO: A = 0.2 >> >> ECHO: A = 0.4 >> >> ECHO: A = 0.6 >> >> ECHO: A = 0.8 >> >> ECHO: A = 1 >> >> >> As you can see repeatedly adding 0.2 slightly overshoots 7.8. This is >> because they are both infinitely recurring binary fractions, not exact >> decimal values. >> >> >> >> On 17 December 2016 at 12:58, Jerry Davis <jdawgaz@gmail.com> wrote: >> >>> It is still that way in the latest snapshot. >>> >>> I looked at the Documentation, and I consider this a bug. >>> >>> The Documentation clearly has floating point values in the start, step, >>> end. And the definitions of start step and end, clearly state that it stops >>> when the next value would be greater. Clearly, not what this does. >>> >>> You should put this in as a bug. >>> >>> Jerry >>> >>> >>> >>> >>> -- >>> 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 Sat, Dec 17, 2016 at 4:07 AM, nop head <nop.head@gmail.com> wrote: >>> >>>> 1/5 is a recurring fraction in binary so it is not surprising. I never >>>> use floating point steps in a for loop. It is much better to use integer >>>> steps and then scale down the loop index >>>> >>>> On 17 December 2016 at 08:03, Johan Jonker <johangjonker@zonnet.nl> >>>> wrote: >>>> >>>>> a workaround is: >>>>> >>>>> for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7); >>>>> for (a=[ 7.2:1/5:8.2]) echo(A=a); >>>>> >>>>> >>>>> >>>>> -- >>>>> View this message in context: http://forum.openscad.org/for- >>>>> statement-doesn-t-do-all-the-steps-sometimes-tp19591p19592.html >>>>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>>>> >>>>> _______________________________________________ >>>>> 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 >>> >>> >> >
NH
nop head
Sat, Dec 17, 2016 1:23 PM

echo (6.8 + 0.2 - 7.0);

echo (6.8 + 0.2 + 0.2 - 7.2);

echo (6.8 + 0.2 + 0.2 + 0.2 - 7.4);

echo (6.8 + 0.2 + 0.2 + 0.2 + 0.2 - 7.6);

echo (6.8 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2 - 7.8);

echo (6.8 + 0.4 + 0.4 - 7.6);

echo (6.8 + 0.8 - 7.6);

echo (6.8 + 0.6 - 7.4);

ECHO: 0

ECHO: 0

ECHO: 0

ECHO: 8.88178e-016

ECHO: 8.88178e-016

ECHO: 8.88178e-016

ECHO: 0

ECHO: -8.88178e-016

So you can't ever rely on sums of floating point numbers hitting exact
values. You might not be surprised if you had numbers like 1/3, 1/6, etc,
but in binary most fractions are not exact.

On 17 December 2016 at 13:09, nop head nop.head@gmail.com wrote:

echo (6.8 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2 - 7.8);

ECHO: 8.88178e-016

On 17 December 2016 at 13:07, nop head nop.head@gmail.com wrote:

Sorry, typo

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

ECHO: A7 = -1

ECHO: A7 = -0.8

ECHO: A7 = -0.6

ECHO: A7 = -0.4

ECHO: A7 = -0.2

ECHO: A7 = 8.88178e-016

ECHO: A = -1

ECHO: A = -0.8

ECHO: A = -0.6

ECHO: A = -0.4

ECHO: A = -0.2

ECHO: A = 0

On 17 December 2016 at 13:05, nop head nop.head@gmail.com wrote:

Use this to see why it doesn't behave as expected:

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

ECHO: A7 = -1

ECHO: A7 = -0.8

ECHO: A7 = -0.6

ECHO: A7 = -0.4

ECHO: A7 = -0.2

ECHO: A7 = 8.88178e-016

ECHO: A = 0

ECHO: A = 0.2

ECHO: A = 0.4

ECHO: A = 0.6

ECHO: A = 0.8

ECHO: A = 1

As you can see repeatedly adding 0.2 slightly overshoots 7.8. This is
because they are both infinitely recurring binary fractions, not exact
decimal values.

On 17 December 2016 at 12:58, Jerry Davis jdawgaz@gmail.com wrote:

It is still that way in the latest snapshot.

I looked at the Documentation, and I consider this a bug.

The Documentation clearly has floating point values in the start, step,
end. And the definitions of start step and end, clearly state that it stops
when the next value would be greater. Clearly, not what this does.

You should put this in as a bug.

Jerry

--
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 Sat, Dec 17, 2016 at 4:07 AM, nop head nop.head@gmail.com wrote:

1/5 is a recurring fraction in binary so it is not surprising. I never
use floating point steps in a for loop. It is much better to use integer
steps and then scale down the loop index

On 17 December 2016 at 08:03, Johan Jonker johangjonker@zonnet.nl
wrote:

a workaround is:

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

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


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

echo (6.8 + 0.2 - 7.0); echo (6.8 + 0.2 + 0.2 - 7.2); echo (6.8 + 0.2 + 0.2 + 0.2 - 7.4); echo (6.8 + 0.2 + 0.2 + 0.2 + 0.2 - 7.6); echo (6.8 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2 - 7.8); echo (6.8 + 0.4 + 0.4 - 7.6); echo (6.8 + 0.8 - 7.6); echo (6.8 + 0.6 - 7.4); ECHO: 0 ECHO: 0 ECHO: 0 ECHO: 8.88178e-016 ECHO: 8.88178e-016 ECHO: 8.88178e-016 ECHO: 0 ECHO: -8.88178e-016 So you can't ever rely on sums of floating point numbers hitting exact values. You might not be surprised if you had numbers like 1/3, 1/6, etc, but in binary most fractions are not exact. On 17 December 2016 at 13:09, nop head <nop.head@gmail.com> wrote: > echo (6.8 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2 - 7.8); > > ECHO: 8.88178e-016 > > On 17 December 2016 at 13:07, nop head <nop.head@gmail.com> wrote: > >> Sorry, typo >> >> for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7 - 7.8); >> for (a=[ 7.2:1/5:8.2]) echo(A=a - 8.2); >> >> ECHO: A7 = -1 >> >> ECHO: A7 = -0.8 >> >> ECHO: A7 = -0.6 >> >> ECHO: A7 = -0.4 >> >> ECHO: A7 = -0.2 >> >> ECHO: A7 = 8.88178e-016 >> >> ECHO: A = -1 >> >> ECHO: A = -0.8 >> >> ECHO: A = -0.6 >> >> ECHO: A = -0.4 >> >> ECHO: A = -0.2 >> >> ECHO: A = 0 >> >> >> >> >> >> On 17 December 2016 at 13:05, nop head <nop.head@gmail.com> wrote: >> >>> Use this to see why it doesn't behave as expected: >>> >>> for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7 - 7.8); >>> for (a=[ 7.2:1/5:8.2]) echo(A=a - 7.2); >>> >>> ECHO: A7 = -1 >>> >>> ECHO: A7 = -0.8 >>> >>> ECHO: A7 = -0.6 >>> >>> ECHO: A7 = -0.4 >>> >>> ECHO: A7 = -0.2 >>> >>> ECHO: A7 = 8.88178e-016 >>> >>> ECHO: A = 0 >>> >>> ECHO: A = 0.2 >>> >>> ECHO: A = 0.4 >>> >>> ECHO: A = 0.6 >>> >>> ECHO: A = 0.8 >>> >>> ECHO: A = 1 >>> >>> >>> As you can see repeatedly adding 0.2 slightly overshoots 7.8. This is >>> because they are both infinitely recurring binary fractions, not exact >>> decimal values. >>> >>> >>> >>> On 17 December 2016 at 12:58, Jerry Davis <jdawgaz@gmail.com> wrote: >>> >>>> It is still that way in the latest snapshot. >>>> >>>> I looked at the Documentation, and I consider this a bug. >>>> >>>> The Documentation clearly has floating point values in the start, step, >>>> end. And the definitions of start step and end, clearly state that it stops >>>> when the next value would be greater. Clearly, not what this does. >>>> >>>> You should put this in as a bug. >>>> >>>> Jerry >>>> >>>> >>>> >>>> >>>> -- >>>> 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 Sat, Dec 17, 2016 at 4:07 AM, nop head <nop.head@gmail.com> wrote: >>>> >>>>> 1/5 is a recurring fraction in binary so it is not surprising. I never >>>>> use floating point steps in a for loop. It is much better to use integer >>>>> steps and then scale down the loop index >>>>> >>>>> On 17 December 2016 at 08:03, Johan Jonker <johangjonker@zonnet.nl> >>>>> wrote: >>>>> >>>>>> a workaround is: >>>>>> >>>>>> for (a7=[ 6.8:1/5:7.800001]) echo(A7=a7); >>>>>> for (a=[ 7.2:1/5:8.2]) echo(A=a); >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> View this message in context: http://forum.openscad.org/for- >>>>>> statement-doesn-t-do-all-the-steps-sometimes-tp19591p19592.html >>>>>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>>>>> >>>>>> _______________________________________________ >>>>>> 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 >>>> >>>> >>> >> >
JJ
Johan Jonker
Sat, Dec 17, 2016 3:36 PM

It is the question if it's a bug.
Maybe it is more important to understand it.

I tried to do the same in VBA.
There the same thing happens.

I more like a warning in the on line manual about the proper use of the
statement.

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

It is the question if it's a bug. Maybe it is more important to understand it. I tried to do the same in VBA. There the same thing happens. I more like a warning in the on line manual about the proper use of the statement. -- View this message in context: http://forum.openscad.org/for-statement-doesn-t-do-all-the-steps-sometimes-tp19591p19603.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Sat, Dec 17, 2016 4:04 PM

It is really proper use of floating point math, nothing OpenSCAD specific.

I always use integer indices and compute everything from those. I think it
has been mentioned before that OpenSCAD could do that internally. I.e.
instead of repeatedly adding it could have a hidden counter that it
multiples the step value by.

echo(6.8 + 5 * 0.2 - 7.8);
ECHO: 0

That would give more accurate results but there would still be caveats.

On 17 December 2016 at 15:36, Johan Jonker johangjonker@zonnet.nl wrote:

It is the question if it's a bug.
Maybe it is more important to understand it.

I tried to do the same in VBA.
There the same thing happens.

I more like a warning in the on line manual about the proper use of the
statement.

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


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

It is really proper use of floating point math, nothing OpenSCAD specific. I always use integer indices and compute everything from those. I think it has been mentioned before that OpenSCAD could do that internally. I.e. instead of repeatedly adding it could have a hidden counter that it multiples the step value by. echo(6.8 + 5 * 0.2 - 7.8); ECHO: 0 That would give more accurate results but there would still be caveats. On 17 December 2016 at 15:36, Johan Jonker <johangjonker@zonnet.nl> wrote: > It is the question if it's a bug. > Maybe it is more important to understand it. > > I tried to do the same in VBA. > There the same thing happens. > > I more like a warning in the on line manual about the proper use of the > statement. > > > > > -- > View this message in context: http://forum.openscad.org/for- > statement-doesn-t-do-all-the-steps-sometimes-tp19591p19603.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >