• R/O
  • SSH

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

A small kernel of code for playing with Galois fields of arbitrary characteristic


Commit MetaInfo

Révision430a429881135d4234982e160ff76cc009132f13 (tree)
l'heure2021-03-15 14:52:04
AuteurEric Hopper <hopper@omni...>
CommiterEric Hopper

Message de Log

Merge in ratpi to grabbag.

Change Summary

Modification

diff -r 3a540f0c7c82 -r 430a42988113 grabbag.py
--- a/grabbag.py Sun Mar 14 22:38:04 2021 -0700
+++ b/grabbag.py Sun Mar 14 22:52:04 2021 -0700
@@ -15,6 +15,7 @@
1515 bitpool >>= 1
1616 --bitpoolbits
1717
18+
1819 def inewt(b, n):
1920 newest = b >> (b.bit_length() - (b.bit_length() // n))
2021 est = 0
@@ -26,6 +27,7 @@
2627 return min(est, newest)
2728 return newest
2829
30+
2931 def factors(n):
3032 factors = []
3133 while n & 1 == 0:
@@ -43,8 +45,10 @@
4345 factors.append(n)
4446 return factors
4547
48+
4649 import math
4750
51+
4852 def nth_root_big(b, n):
4953 if b.bit_length() <= 1023:
5054 return math.pow(b, 1/n)
@@ -58,3 +62,13 @@
5862 while (len(flist) > 0) and (runprod < chop_factor):
5963 runprod *= flist.pop()
6064 return math.pow(inewt(b, runprod), 1 / (n // runprod))
65+
66+
67+from fractions import Fraction as F
68+
69+
70+def ratpi(n):
71+ """I have no better place to put this. This is a quickly converging series
72+ for computing a rational approximation of pi. For when you want more
73+ precision than math.pi will give you."""
74+ return sum(F(1/16**k)*(F(4,8*k+1) - F(2,8*k + 4) - F(1,8*k+5) - F(1, 8*k+6)) for k in range(0, n))
diff -r 3a540f0c7c82 -r 430a42988113 ratpi.py
--- a/ratpi.py Sun Mar 14 22:38:04 2021 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
1-from fractions import Fraction as F
2-
3-"""I have no better place to put this. This is a quickly converging series for
4-computing a rational approximation of pi. For when you want more precision
5-than math.pi will give you."""
6-
7-def ratpi(n):
8- return sum(F(1/16**k)*(F(4,8*k+1) - F(2,8*k + 4) - F(1,8*k+5) - F(1, 8*k+6)) for k in range(0, n))