Post Reply 
sin(x) & cos(x) for x = 10²² in radians
10-02-2023, 10:59 PM
Post: #15
RE: sin(x) & cos(x) for x = 10²² in radians
(10-02-2023 04:10 PM)dm319 Wrote:  Interesting!

Any ideas why this is is difficult to answer?

Presumably relates to finding where 10^22 falls in the way of full turns plus radians?

Problem is cost of storing the constants, and the extra code to make it work.
Benefit may not be forthcoming, since float may represent a range (error ≤ 1/2 ulp)

To reduce costly arbitrary precision math, constants may be precomputed.
Lots of digits of pi itself doesn't work, if we can't efficiently do mod (2 pi)

This is how intel-decimal library does this (used in Free42/Plus42), turning mod (2 pi) to dot-products.
static BID_UINT384 bid_decimal128_moduli Wrote:// Values of (10^a / (2 pi)) mod 1 for -35 <= a <= 6111
// Each one is a 384-bit binary fraction. This may be a bit too much!
// My rough guideline is a bit more than 3x the working precision
...

384 bits = 48 bytes
Array length = 6111 - (-35) + 1 = 6147      → table size of almost 300K !

I recently downloaded Python 3.8.9 for my Win7 laptop. It had fixed the issue.

p3> from cmath import *
p3> exp(1e22j) # = cis(1e22)
(0.523214785395139-0.8522008497671888j)
p3> log(_).imag # reduced angle
-1.020177392559087

Older python work too (below is Python 2.6.6), if we use gmpy2

p2> from gmpy2 import *
p2> exp(1e22j)
mpc('0.52321478539513899-0.85220084976718879j')
p2> log(_).imag
mpfr('-1.0201773925590869')

Chez Scheme 9.5 fixed this too (newer version here)

scheme> (exp 0+1e22i)
0.523214785395139-0.8522008497671888i
scheme> (imag-part (log last))
-1.020177392559087

Another way to get arg(cis(θ)) is 2*atan(tan(θ/2))
RHS form is cheaper to compute.

Free42/Plus42:
Note: angle reduction code honors DEG/RAD/GRAD mode. I am not sure to count this as feature or bug.
Code:
00 { 13-Byte Prgm }
01▸LBL "A↓"
02 2
03 ÷
04 TAN
05 ATAN
06 ENTER
07 +
08 END

XEQ "RAD" 1e22 XEQ "A↓"      → -1.020177392559086973318201985281164

A convergent of pi (53 bits numerator) = 5706674932067741/1816491048114374

5706674932067741 XEQ "A↓" → 4.237546464512562184164292621941626e-16
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: sin(x) & cos(x) for x = 10²² in radians - Albert Chan - 10-02-2023 10:59 PM



User(s) browsing this thread: 3 Guest(s)