Skip to content

A set of Python 3 defined functions. They can provide high decimal precision calculations using numbers in "str" format. The algorithms used are the same as those used when performing the calculations by hand. All using Python 3 built-in functions.

License

Notifications You must be signed in to change notification settings

artmenlope/high-precision-calculations-str

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

high-precision-calculations-str

License: MIT Last Commit

A set of Python 3 defined functions. They can provide high decimal precision calculations using numbers in str format. The algorithms used are the same as those used when performing the calculations by hand. All using Python 3 built-in functions.

Usage

If you don't have the high_precision_calculations.py script placed in your working directory, the functions can be imported, for example, by using

import sys
path = "<path to the folder where the script is stored>"
sys.path.insert(0, path)
import high_precision_calculations

As a practical example, for calculating the value of the golden ratio $\varphi = (1+\sqrt{5})/2$ with an accuracy of up to 50 decimal places we would type

divide_str(sum_str("1", sqrt_str("5", decimal_prec=50)), "2", decimal_prec=50)

or

divide_str(sum_str("1", sqrt_str("5", 50)), "2", 50)

which should return

'1.61803398874989484820458683436563811772030917980576'

To see the output of the functions in this example using 15000 decimals see the file phi_15000_decimals.txt


List of auxiliar functions:

  • num_decims(num)
  • max_num_decims(num1, num2)
  • num_zeros_init(num)
  • num_zeros_end(num)
  • del_decim_zeros(num)
  • decim_modif_str(num1, num2)
  • make_pairs(txt)

List of main functions:

Function name Use
sum_str(num1, num2) Addition.
subt_str(num1, num2) Subtraction.
multiply_str(num1, num2) Multiplication.
divide_str(dividend, divider, decimal_prec=16) Division.
sqrt_str(num, decimal_prec=16) Square root.
power_str(num, powr) Power (the argument "powr" must be a positive integer).

About

A set of Python 3 defined functions. They can provide high decimal precision calculations using numbers in "str" format. The algorithms used are the same as those used when performing the calculations by hand. All using Python 3 built-in functions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages