octave-intinf Code
Infinite-precision integer arithmetic for Octave, written in Octave
Brought to you by:
etienne
Copyright (C) 2018 Etienne Grossmann <etienne@users.sourceforge.net>
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, see <http://www.gnu.org/licenses/>.
This folder contains Octave code to perform arbitrary-precision integer
arithmetic. It may or may not work in Matlab.
The supported operations are:
>> s = a = intinf (126) % Creation of intinf-class object from integer or string
s = 126
>> b = intinf ('-792716404922304611755050042308687')
b = -792716404922304611755050042308687
>> c = a + b % Addition
c = -792716404922304611755050042308561
>> d = a - b % Subtraction
d = 792716404922304611755050042308813
>> e = c * d % Multiplication
e = -628399298632943207296804593622614025887290777301864028724995648093
>> f = (e - a^2) / b % Exponentiation, division
f = 792716404922304611755050042308687
>> f == -b % Logical operators
ans = 1
>> [q, r] = intinf_divide (b^2, a) % Divsion and remainder
q = 4987296020896374661085750743036619253073736327792571656547584634
r = 85
>> r < a
ans = 1
>> x = intinf_rand (100) % Random number (here, with 100 digits)
x = 5957920324041182863967505832677200714276564790135557044108872634353981714576255029666518574621376764
>> tic, a^a, toc % Don't be in a big hurry
ans = 4432907660220782149197257457170010056248664733961715006433455717789043517106373872170818953941792055669609014893218047089803712563472169065833738899530142657476809234058293370126853817068631046152741967763913240019546541793769190722594113575550312228000452759781376
Elapsed time is 2.70419 seconds.
For faster calculations, you may want to consider the "symbolic" package of
Octave-forge https://octave.sourceforge.io/symbolic
Code organization:
* This directory contains non-class m-files, e.g. intinf_div() and the back-end
functions that actually perform the calculations, e.g. apia_add(),
app_mul(). "apia" stands for "arbitrary-precision integer arithmetic". The
integers are represented as strings. These functions take double or string
arguments.
* The sub-directory @intinf contains the class m-files, e.g. intinf(), times().
TODO:
* Better errors.
* Make a package loadable by octave's pkg function.