Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Issue rounding Apéry's constant
- PhysicsLover999
- Scratcher
100+ posts
Issue rounding Apéry's constant
So in this project, I try to calculate a constant that's supposed to come out to 1.2020569031595942853997381…, according to Wikipedia. Scratch, being Scratch, decided to round this to 1.202057, and I would like a number with a decimal a little bigger than 6 digits.
Apéry's constant:
1 + 1/2^3 + 1/3^3 + 1/4^3
HelpI'mNewToATPleaseDontHurtMe
Apéry's constant:
1 + 1/2^3 + 1/3^3 + 1/4^3
HelpI'mNewToATPleaseDontHurtMe
“Two things are infinite: the universe and human stupidity; and I’m not sure about th’universe!” - Albert Einstein
- TheMonsterOfTheDeep
- Scratcher
1000+ posts
Issue rounding Apéry's constant
There are two main things to note:
- Scratch's variable watchers do not show numbers to full precision. To see a number to the full precision that Scratch stores it at, do something like this:
set [watcher v] to (join [ ] (apery's constant)) // where the first argument in the join block is a space.
- Apery's constant takes a huge amount of iterations to calculate to a large precision - I matched the decimal only up to 1.20205690315 with 10 million iterations.
my latest extension: 2d vector math
- PhysicsLover999
- Scratcher
100+ posts
Issue rounding Apéry's constant
There are two main things to note:
- Scratch's variable watchers do not show numbers to full precision. To see a number to the full precision that Scratch stores it at, do something like this:
set [watcher v] to (join [ ] (apery's constant)) // where the first argument in the join block is a space.- Apery's constant takes a huge amount of iterations to calculate to a large precision - I matched the decimal only up to 1.20205690315 with 10 million iterations.
Thanks!! I did 10mil before sharing, and it didn't change - that's when I figured something was probably wrong.
“Two things are infinite: the universe and human stupidity; and I’m not sure about th’universe!” - Albert Einstein
- gtoal
- Scratcher
1000+ posts
Issue rounding Apéry's constant
There are two main things to note:
- Scratch's variable watchers do not show numbers to full precision. To see a number to the full precision that Scratch stores it at, do something like this:
set [watcher v] to (join [ ] (apery's constant)) // where the first argument in the join block is a space.- Apery's constant takes a huge amount of iterations to calculate to a large precision - I matched the decimal only up to 1.20205690315 with 10 million iterations.
I don't know about a table of reciprocals of cubes, but for generating a series of cubes there's an efficient algorithm that just uses adds and the value of the previous cube. (and generates a table of squares incidentally as they're also needed in the expansion of (X+1)^3 in terms of X, X^2 and X^3.)
Here's the code in C (sort of), simplified to make it easier to translate into assembly code after getting the algorithm correct in C first…
http://www.gtoal.com/src/squares/cubes.c
With Scratch's interpretive overhead swamping the cost of floating point maths, this probably won't help in a Scratch version but I thought you might find it amusing anyway. As explained in the comment, this was given as a programming exercise for new programmers of the Deuce computer at Kidsgrove in the late 50's. (I wasn't around then of course but I thought I'd try the exercise to see how hard it was…)
G
Last edited by gtoal (May 22, 2017 21:50:14)
- Discussion Forums
- » Advanced Topics
- » Issue rounding Apéry's constant