Trigonometric/transcendental function accuracy

General discussion about calculators, SwissMicros or otherwise
User avatar
pauli
Posts: 252
Joined: Tue May 02, 2017 10:11 am
Location: Australia

Re: Trigonometric/transcendental function accuracy

Post by pauli »

The long division like approach to square root was taught in schools here when I was young.
The disadvantage with respect to Newton's is that the convergence is linear. Each iteration gives two more digits rather than doubling the number of correct digits. I suspect it's also more complex to implement.
User avatar
rudi
Posts: 415
Joined: Wed Nov 03, 2021 9:03 am
Location: Denmark
Contact:

Re: Trigonometric/transcendental function accuracy

Post by rudi »

My implementation was definetly an iteration approach, and from my memory, I am 99% certain, that it was Newton-Raphson.
The code was based on some code I found in a magazine, either BYTE or Dr. Dobbs Journal, that represented floating point numbers and did basic arithmetic, +-*/. It sounds easy enough, but the assembler code was complex.
/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
User avatar
dm319
Posts: 144
Joined: Thu Aug 03, 2017 12:21 pm
Location: Birmingham, UK

Re: Trigonometric/transcendental function accuracy

Post by dm319 »

The Intel Decimal Point LIbrary, if you look at the source code, in dpml_sqrt.c, there are some interesting comments.

One appears to be a proof of Tuckerman's Rounding, a bit on Newton's iteration, and lots of comments, exclamation marks, and even bits left like this:


#elif SQRT && (F_PRECISION <= 24) && (B_PRECISION < 2*F_PRECISION)

/* This case is unlikely enough that we will worry about it
when we need to (if ever). There is code in older versions of
sqrt that does a tuckermans rounding on single prec values. */

# error "We need to worry about it now."


It is all way above my head, but weirdly fascinating.
SN:09075
User avatar
rudi
Posts: 415
Joined: Wed Nov 03, 2021 9:03 am
Location: Denmark
Contact:

Re: Trigonometric/transcendental function accuracy

Post by rudi »

Lovely. Sometimes, I wish I could go back three or four decades. I also think that the beer tasted better back then…
/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
User avatar
dm319
Posts: 144
Joined: Thu Aug 03, 2017 12:21 pm
Location: Birmingham, UK

Re: Trigonometric/transcendental function accuracy

Post by dm319 »

rudi wrote:
Fri Apr 14, 2023 9:08 pm
Lovely. Sometimes, I wish I could go back three or four decades. I also think that the beer tasted better back then…
The 90s were a golden age. We didn't realise it at the time!
SN:09075
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: Trigonometric/transcendental function accuracy

Post by Walter »

Fun fact: golden ages exist only in the past. 8-)
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
User avatar
akaTB
Posts: 794
Joined: Tue May 02, 2017 1:56 pm
Location: Milan, Italy

Re: Trigonometric/transcendental function accuracy

Post by akaTB »

dm319 wrote:
Sat May 06, 2023 2:59 pm
rudi wrote:
Fri Apr 14, 2023 9:08 pm
Lovely. Sometimes, I wish I could go back three or four decades. I also think that the beer tasted better back then…
The 90s were a golden age. We didn't realise it at the time!
Maybe you meant Golden Ale.
:lol:
Greetings,
    Massimo
ajcaton
-+×÷ left is right and right is wrong :twisted: Casted in gold
User avatar
dm319
Posts: 144
Joined: Thu Aug 03, 2017 12:21 pm
Location: Birmingham, UK

Re: Trigonometric/transcendental function accuracy

Post by dm319 »

Walter wrote:
Sat May 06, 2023 3:14 pm
Fun fact: golden ages exist only in the past. 8-)
True. Much like being too drunk.
SN:09075
BigEd
Posts: 71
Joined: Wed May 03, 2017 9:00 am

Re: Trigonometric/transcendental function accuracy

Post by BigEd »

whuyse wrote:
Sun Mar 26, 2023 2:29 pm
Older HPs (the 41, and its emulator DM-41X) also show the problem for SIN(x) for x close to PI;
eg. PI SIN (in RAD mode of course..) returns -4.1E-10 on a 41.
I'm not sure which model was first, but certainly the 42S and its faithful simulator Free42 (and thus, the DM42) get it right, the latter even all 34 digits ;-)

PI = 3.141592653589793238462643383279503
SIN(PI) = -1.158028306006248941790250554076922E-34
PI + SIN(PI) = 3.1415926535897932384626433832795028841971693993751058209749445923078

Cheers, Werner
I'm quite surprised to see the C47 (C43) simulator shows a very reduced precision result in this case - is this expected? I was hoping for very similar accuracy to Free42.
PI = 3.141592653589793238462643383279503
SIN(PI) = -1.1580283060062489E-34
User avatar
pauli
Posts: 252
Joined: Tue May 02, 2017 10:11 am
Location: Australia

Re: Trigonometric/transcendental function accuracy

Post by pauli »

My (unsupported) supposition is that Free42 is incorrectly rounding which cascades to a less reliable result.

I am very much aware that Intel's decimal library has rounding issues in the last digit at times.
I'm not aware of any such issues in the WP 34S firmware.


Pauli
Post Reply