Out of curiosity I calculated cos(1.57079632) on two Casio calculators in radians.
fx-6300G : 6.8 x 10-9
fx-115W : 6.795 x 10-9
Surprised at these results, both of these were quite highly regarded scientific calculators, especially the first one.
Trigonometric/transcendental function accuracy
Re: Trigonometric/transcendental function accuracy
Just for comparison: RAD 1.57079632 cos on the WP43 returns 6.794 896 619 231 321 639 352 319 743 005 672 × 10^-9 which matches WolframAlpha's result 6.794 896 619 231 321 639 352 319 743 005 671 63... × 10^-9.
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
Re: Trigonometric/transcendental function accuracy
There's also a german site with many many "insides", also describing the tools etc.
https://www.richis-lab.de/, e.g. https://www.richis-lab.de/cpu.htm,
Controllers from Calculators: https://www.richis-lab.de/calc.htm
Howto: https://www.richis-lab.de/Howto.htm
[ HP48/49/50/42S/WP34/HP Prime/ DM42 (#00185+00318) ]
Re: Trigonometric/transcendental function accuracy
it’s got nothing to do with the Quake algorithm.
I was coding assembler in the 80’ies, on paper (!!!). So I was manually executing the program on paper instruction by instruction, using 13 to test. That’s why I will never forget 3,605551275
Quake magic/woodo algorithm, see this:
https://youtu.be/p8u_k2LIZyo
/Rudi
DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
Re: Trigonometric/transcendental function accuracy
That's fascinating, do you have your algorithm still? I have utterly no idea how you would go about this. Did your processor have instructions for multiply and divide?
SN:09075
Re: Trigonometric/transcendental function accuracy
Im affraid my notes are lost. I made the assembler code, but never actually got it implemented. The processor had MULT and DIV, but only integers.
I don’t quite remember the algorithm I was implementing, but I think I got it from “Mathematics for the Millions” by Lancelot Hogben. I’ll try digging it out, next time a dare to go on a mission to our attic
/Rudi
DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
Re: Trigonometric/transcendental function accuracy
The usual approach to computing square root is to get a rough approximation (often the initial number is used) and then apply Newton iterations to refine it. Each iteration of Newtons is fairly quick (one addition and a division/reciprocal from memory) and convergence is quadratic (i.e. it doubles the number of correct digits each step).
The only concern is that it doesn't always converge to a fixed value (i.e. the result can oscillate between iterations) so the convergence check needs to account for this. This is common for many numeric algorithms so it's not really a problem.
The actual iteration used is:
` x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} = x_n - \frac{x_n^2-x_0}{2x_n} = x_n - \frac{1}{2} ( x_n - \frac{x_0}{x_n} )`
instead of `x_0` here, it is okay to use 1 to change the division into a reciprocal. The iteration still needs to start at `x_0` if this is done.
The only concern is that it doesn't always converge to a fixed value (i.e. the result can oscillate between iterations) so the convergence check needs to account for this. This is common for many numeric algorithms so it's not really a problem.
The actual iteration used is:
` x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} = x_n - \frac{x_n^2-x_0}{2x_n} = x_n - \frac{1}{2} ( x_n - \frac{x_0}{x_n} )`
instead of `x_0` here, it is okay to use 1 to change the division into a reciprocal. The iteration still needs to start at `x_0` if this is done.
Re: Trigonometric/transcendental function accuracy
I think my approach was much simpler, probably using a Newton-Raphson approachpauli wrote: ↑Mon Apr 10, 2023 3:51 amThe usual approach to computing square root is to get a rough approximation (often the initial number is used) and then apply Newton iterations to refine it. Each iteration of Newtons is fairly quick (one addition and a division/reciprocal from memory) and convergence is quadratic (i.e. it doubles the number of correct digits each step).
The only concern is that it doesn't always converge to a fixed value (i.e. the result can oscillate between iterations) so the convergence check needs to account for this. This is common for many numeric algorithms so it's not really a problem.
The actual iteration used is:
` x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} = x_n - \frac{x_n^2-x_0}{2x_n} = x_n - \frac{1}{2} ( x_n - \frac{x_0}{x_n} )`
instead of `x_0` here, it is okay to use 1 to change the division into a reciprocal. The iteration still needs to start at `x_0` if this is done.
\(x_{i+1}=\dfrac{x_i + \dfrac{n}{x_i} }{2}\)
n = 13
x0 = 3 =>
3,666666667
3,606060606
3,605551311
3,605551275
Edit:
Wait a minute, I think it’s the exact same iteration as you show
/Rudi
DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
Re: Trigonometric/transcendental function accuracy
Yes, it's the same
It's quick and easy and fast to converge. With a decent initial estimate, a small fixed number of iterations can be used.
The algorithm used in Quake uses a good first estimate and a single Newton-Raphson iteration from memory.
It's quick and easy and fast to converge. With a decent initial estimate, a small fixed number of iterations can be used.
The algorithm used in Quake uses a good first estimate and a single Newton-Raphson iteration from memory.
Re: Trigonometric/transcendental function accuracy
Hello,
I remember coding in Z80 assembly the algorithm of the written square root, analog to a written division ... and no need of approximation series
Pekis
I remember coding in Z80 assembly the algorithm of the written square root, analog to a written division ... and no need of approximation series
Pekis