Python Forum
Gmpy2 Newbie Working on Precision
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gmpy2 Newbie Working on Precision
#1
I am trying to calculate minute angles, and would like precision of at least 15 digits:

But I fail to understand how Python is rounding.

As I vary the value of asin by factors of 10 (from .001 to .00001), the output adds these zeros between the leading numeral 1 and the next numeral 1 (and some sixes after). See the image below.

And this is happening whether I use the gimpy2 or math modules:

Does the Sin-1 actually do this on radians?

Degrees acts similarly: When the input is very small and changes by a factor of ten (eg., .001 - .00001), the output of asin only changes by a factor of ten — the decimal point just moves one place while leaving the significant figures virtually unchanged.

Confused

   

Thank you!!

A version of the test code being used is shown below:

import gmpy2
import math
from gmpy2 import *
from gmpy2 import get_context as ctx

ctx().precision = 100

# L = mpfr('1000.0')
F = 0.00001
N = 10.0
B = 0.5

C = gmpy2.div(F, N)
c = F / N
D = 2 * C
d = 2 * c

E = B * gmpy2.asin(D)
e = B * math.asin(d)

g = .000002
e2 = B * math.asin(g)
# F = gmpy2.mul(B, E)
# sin(2 * theta) = 2 * sin(theta)cos(theta)

# print("L: ", L, type(L))
print("F: ", F, type(F))
print("N: ", N, type(N))

print("B: ", B, type(B))
print("C: ", C, type(C))
print("c: ", c, type(c))
print("D: ", D, type(D))
print("d: ", d, type(d))

print("E: ", E, type(E))
print("e: ", e, type(e))

print("e2: ", e2, type(e2))

print(ctx())
Reply
#2
Maybe this is a clue. I get this error:

get_context.round = RoundUp

AttributeError: 'builtin_function_or_method' object has no attribute 'round'
Reply
#3
I went to a random calculator website: https://math.tools/calculator/trignometry/asin

From there I found similar results and created a table of the values (see image below):

   

I know the circle looks pretty flat (linear), when the angle is very small, but the radian numbers are just spooking me (the zeros and sixes).

On the other hand, the values in the "Degrees" column in the table do not look so bad — they change in a way that does not appear as weird. Maybe degrees are a more comforting unit to work with in this case (and they are about 60 times smaller than radians). Blush
Reply
#4
get_context().round works, sorry.
Reply
#5
(Jan-22-2024, 03:44 AM)charlesrkiss Wrote: I went to a random calculator website: https://math.tools/calculator/trignometry/asin

From there I found similar results and created a table of the values (see image below):


I know the circle looks pretty flat (linear), when the angle is very small, but the radian numbers are just spooking me (the zeros and sixes).

On the other hand, the values in the "Degrees" column in the table do not look so bad — they change in a way that does not appear as weird. Maybe degrees are a more comforting unit to work with in this case (and they are about 60 times smaller than radians). Blush

The values look fine to me. Some

Assuming is in radian, x is between -1 and 1, then asin(x) can be approximated by x + (x**3 / 6) + (3 * x**5 / 40) + ....

Let's try it with x =0.01.

asin(0.01) = 0.01 + (0.000001/6) + (3 *0.0000000001/40)

which becomes

asin(0.01) = 0.01 + 0.000000166666666... + 0.0000000000075

or

0.010000166674166668

Sorry about the lack of formatting and terseness.
Reply
#6
Thank you Case.

JTLYK, I spent hours carefully looking into the significands (see video), first and second 'derivatives,' and stretching limits (see image), including working with the different rounding types. And yes, it is ALL PERFECT and SO impressive.

Some plots using RoundToNearest, when I was at the limit:

   

I'm so grateful for your help, and putting me on the right track. Gmpy2 works exactly as expected, once I started moving up the learning curve a bit. Now I can get back to the actual math (that I virtually forgot over these last few days). LOL

I would like to add that I use the GNU graphics software GIMP a lot, and it's really funny that I keep adding a letter "I" and must backspace to delete it. LOL

If you need any images and I could save you some time, please let me know.

Thank you so much !!!


.mp4   forum.mp4 (Size: 1,020.1 KB / Downloads: 13)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Precision with Decimal Type charlesrkiss 9 752 Jan-18-2024, 06:30 PM
Last Post: charlesrkiss
  Precision conversion garynewport 2 954 Oct-19-2022, 10:47 AM
Last Post: garynewport
Photo Filtering data and precision during calculations Scientifix 0 1,788 Mar-30-2021, 01:00 PM
Last Post: Scientifix
  High-Precision Board Voltage Reading from Python into PD Liam484 1 2,094 Mar-29-2021, 02:57 PM
Last Post: Marbelous
  Decimal (Global precision setting) Valentina 3 3,648 Aug-23-2019, 11:53 AM
Last Post: Valentina
  python decimal scale precision massimo_m 5 5,440 Aug-22-2019, 11:47 AM
Last Post: perfringo
  Trouble with decimal precision Cassie 4 3,141 Feb-14-2019, 08:23 PM
Last Post: Cassie
  precision error chris64 1 2,243 Nov-29-2017, 09:40 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020