For instance, if B = 10000, the number is represented internally as [3456, 7890, 12].

Similar documents
my $y = Math::BigRat->new('inf'); print "$y ", ($y->is_inf? 'is' : 'is not'), " infinity\n";

my $y = Math::BigRat->new('inf'); print "$y ", ($y->is_inf? 'is' : 'is not'), " infinity\n";

print inf + 42,"\n"; print NaN * 7,"\n"; print hex("0x "),"\n"; # Perl v or later

# Configuration methods (may be used as class methods and instance methods)

my $pi = Math::BigFloat->bpi(100); # PI to 100 digits

NAME SYNOPSIS. Perl version documentation - Math::BigFloat. Math::BigFloat - Arbitrary size floating point math package. use Math::BigFloat;

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Arithmetic and Bitwise Operations on Binary Data

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Chapter 4. Operations on Data

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

CS61B Lecture #14: Integers. Last modified: Wed Sep 27 15:44: CS61B: Lecture #14 1

Javascript Bignum Extensions

Module 2: Computer Arithmetic

Arithmetic and Bitwise Operations on Binary Data

Calculations. 4.1 Check if a number is a prime

Bits, Words, and Integers

Operators. Java operators are classified into three categories:

CS61B Lecture #14: Integers

Floating Point January 24, 2008

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Chapter 1 An Introduction to Computer Science. INVITATION TO Computer Science 1

Number System. Introduction. Decimal Numbers

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

Divide: Paper & Pencil

UNIT 3 OPERATORS. [Marks- 12]

Python Numbers. Learning Outcomes 9/19/2012. CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 Discussion Sections 02-08, 16, 17

Number Systems CHAPTER Positional Number Systems

Programming in C++ 5. Integral data types

CS & IT Conversions. Magnitude 10,000 1,

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

Lecture 8: Addition, Multiplication & Division

Octal & Hexadecimal Number Systems. Digital Electronics

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

2. Integers. 9 * celsius / Celsius to Fahrenheit. Precedence. (9 * celsius / 5) + 32

Number Systems and Number Representation

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

2. Integers. 9 * celsius / Celsius to Fahrenheit. Precedence. (9 * celsius / 5) + 32

Internal Data Representation

Foundations of Computer Systems

2. Integers. 9 * celsius / Celsius to Fahrenheit. Precedence. (9 * celsius / 5) + 32

Introduction to C Language

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Consider the actions taken on positive integers when considering decimal values shown in Table 1 where the division discards the remainder.


System Programming CISC 360. Floating Point September 16, 2008

Floating point. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.

Operators and Expressions:

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

1/31/2017. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types

CHAPTER 2 Data Representation in Computer Systems

Practical Numerical Methods in Physics and Astronomy. Lecture 1 Intro & IEEE Variable Types and Arithmetic

More Natural Arithmetic in C++

Floating Point. CSE 238/2038/2138: Systems Programming. Instructor: Fatma CORUT ERGİN. Slides adapted from Bryant & O Hallaron s slides

9/2/2016. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

CHAPTER 2 Data Representation in Computer Systems

COMP2121: Microprocessors and Interfacing. Number Systems

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

Giving credit where credit is due

Bits, Bytes, and Integers

Programming I Lecture 7

FAQ No. 53. ihost: Logic Points. Roles and Privileges. Adding and removing logic points. Accessing and using the Logic Editor

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Giving credit where credit is due

Computer Arithmetic. Appendix A Fall 2003 Lec.03-58

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design

Reserved Words and Identifiers

9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

Computer Organisation CS303

Number representations

Organisasi Sistem Komputer

World Inside a Computer is Binary

Number Systems and Their Representations

Computers Programming Course 6. Iulian Năstac

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

Learning the Binary System

Number Systems and Computer Arithmetic

Chapter 2 Data Representations

Chapter 3 Basic Data Types. Lecture 3 1

Ch. 7 Error Detection and Correction

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Chapter Two MIPS Arithmetic

JAVA OPERATORS GENERAL

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

COMP 122/L Lecture 2. Kyle Dewey

CHAPTER 5: Representing Numerical Data

CS 64 Week 1 Lecture 1. Kyle Dewey

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Introduction to Computer Systems Recitation 2 May 29, Marjorie Carlson Aditya Gupta Shailin Desai

Transcription:

NAME SYNOPSIS DESCRIPTION Math::BigInt::Calc - Pure Perl module to support Math::BigInt This library provides support for big integer calculations. It is not intended to be used by other modules. Other modules which support the same API (see below) can also be used to support Math::BigInt, like Math::BigInt::GMP and Math::BigInt::Pari. In this library, the numbers are represented in base B = 10**N, where N is the largest possible value that does not cause overflow in the intermediate computations. The base B elements are stored in an array, with the least significant element stored in array element zero. There are no leading zero elements, except a single zero element when the number is zero. For instance, if B = 10000, the number 1234567890 is represented internally as [3456, 7890, 12]. THE Math::BigInt API In order to allow for multiple big integer libraries, Math::BigInt was rewritten to use a plug-in library for core math routines. Any module which conforms to the API can be used by Math::BigInt by using this in your program: use Math::BigInt lib => 'libname'; General Notes API version 1 API version Constructors 'libname' is either the long name, like 'Math::BigInt::Pari', or only the short version, like 'Pari'. A library only needs to deal with unsigned big integers. Testing of input parameter validity is done by the caller, so there is no need to worry about underflow (e.g., in _sub() and _dec()) nor about division by zero (e.g., in _div()) or similar cases. For some methods, the first parameter can be modified. That includes the possibility that you return a reference to a completely different object instead. Although keeping the reference and just changing its contents is preferred over creating and returning a different reference. Return values are always objects, strings, Perl scalars, or true/false for comparison routines. The following methods must be defined in order to support the use by Math::BigInt v1.70 or later. api_version() _new(str) _zero() Return API version as a Perl scalar, 1 for Math::BigInt v1.70, 2 for Math::BigInt v1.83. Convert a string representing an unsigned decimal number to an object representing the same number. The input is normalize, i.e., it matches ^(0 [1-9]\d*)$. Return an object representing the number zero. _one() Return an object representing the number one. _two() Return an object representing the number two. Page 1

_ten() Return an object representing the number ten. _from_bin(str) Return an object given a string representing a binary number. The input has a '0b' prefix and matches the regular expression ^0[bB](0 1[01]*)$. _from_oct(str) Return an object given a string representing an octal number. The input has a '0' prefix and matches the regular expression ^0[1-7]*$. _from_hex(str) Mathematical functions Return an object given a string representing a hexadecimal number. The input has a '0x' prefix and matches the regular expression ^0x(0 [1-9a-fA-F][\da-fA-F]*)$. Each of these methods may modify the first input argument, except _bgcd(), which shall not modify any input argument, and _sub() which may modify the second input argument. _add(obj1, OBJ2) Returns the result of adding OBJ2 to OBJ1. _mul(obj1, OBJ2) Returns the result of multiplying OBJ2 and OBJ1. _div(obj1, OBJ2) Returns the result of dividing OBJ1 by OBJ2 and truncating the result to an integer. _sub(obj1, OBJ2, FLAG) _sub(obj1, OBJ2) _dec(obj) _inc(obj) Returns the result of subtracting OBJ2 by OBJ1. If flag is false or omitted, OBJ1 might be modified. If flag is true, OBJ2 might be modified. Decrement OBJ by one. Increment OBJ by one. _mod(obj1, OBJ2) _sqrt(obj) _root(obj, N) _fac(obj) Return OBJ1 modulo OBJ2, i.e., the remainder after dividing OBJ1 by OBJ2. Return the square root of the object, truncated to integer. Return Nth root of the object, truncated to int. N is >= 3. Return factorial of object (1*2*3*4*...). _pow(obj1, OBJ2) Return OBJ1 to the power of OBJ2. By convention, 0**0 = 1. _modinv(obj1, OBJ2) Page 2

Return modular multiplicative inverse, i.e., return OBJ3 so that (OBJ3 * OBJ1) % OBJ2 = 1 % OBJ2 The result is returned as two arguments. If the modular multiplicative inverse does not exist, both arguments are undefined. Otherwise, the arguments are a number (object) and its sign ("+" or "-"). The output value, with its sign, must either be a positive value in the range 1,2,...,OBJ2-1 or the same value subtracted OBJ2. For instance, if the input arguments are objects representing the numbers 7 and 5, the method must either return an object representing the number 3 and a "+" sign, since (3*7) % 5 = 1 % 5, or an object representing the number 2 and "-" sign, since (-2*7) % 5 = 1 % 5. _modpow(obj1, OBJ2, OBJ3) Return modular exponentiation, (OBJ1 ** OBJ2) % OBJ3. _rsft(obj, N, B) Shift object N digits right in base B and return the resulting object. This is equivalent to performing integer division by B**N and discarding the remainder, except that it might be much faster, depending on how the number is represented internally. For instance, if the object $obj represents the hexadecimal number 0xabcde, then _rsft($obj, 2, 16) returns an object representing the number 0xabc. The "remainer", 0xde, is discarded and not returned. _lsft(obj, N, B) Bitwise operators Shift the object N digits left in base B. This is equivalent to multiplying by B**N, except that it might be much faster, depending on how the number is represented internally. _log_int(obj, B) Return integer log of OBJ to base BASE. This method has two output arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ is the exact result, 0 if the result was truncted to give OBJ, and undef if it is unknown whether OBJ is the exact result. _gcd(obj1, OBJ2) Return the greatest common divisor of OBJ1 and OBJ2. Each of these methods may modify the first input argument. _and(obj1, OBJ2) Return bitwise and. If necessary, the smallest number is padded with leading zeros. _or(obj1, OBJ2) Boolean operators Return bitwise or. If necessary, the smallest number is padded with leading zeros. _xor(obj1, OBJ2) _is_zero(obj) _is_one(obj) _is_two(obj) Return bitwise exclusive or. If necessary, the smallest number is padded with leading zeros. Returns a true value if OBJ is zero, and false value otherwise. Returns a true value if OBJ is one, and false value otherwise. Page 3

_is_ten(obj) _is_even(obj) _is_odd(obj) String conversion Returns a true value if OBJ is two, and false value otherwise. Returns a true value if OBJ is ten, and false value otherwise. Return a true value if OBJ is an even integer, and a false value otherwise. Return a true value if OBJ is an even integer, and a false value otherwise. _acmp(obj1, OBJ2) _str(obj) _as_bin(obj) _as_oct(obj) Compare OBJ1 and OBJ2 and return -1, 0, or 1, if OBJ1 is less than, equal to, or larger than OBJ2, respectively. Return a string representing the object. The returned string should have no leading zeros, i.e., it should match ^(0 [1-9]\d*)$. Return the binary string representation of the number. The string must have a '0b' prefix. Return the octal string representation of the number. The string must have a '0x' prefix. Note: This method was required from Math::BigInt version 1.78, but the required API version number was not incremented, so there are older libraries that support API version 1, but do not support _as_oct(). _as_hex(obj) Numeric conversion Miscellaneous _num(obj) _copy(obj) _len(obj) _zeros(obj) Return the hexadecimal string representation of the number. The string must have a '0x' prefix. _digit(obj, N) _check(obj) Given an object, return a Perl scalar number (int/float) representing this number. Return a true copy of the object. Returns the number of the decimal digits in the number. The output is a Perl scalar. Return the number of trailing decimal zeros. The output is a Perl scalar. Return the Nth digit as a Perl scalar. N is a Perl scalar, where zero refers to the rightmost (least significant) digit, and negative values count from the left (most significant digit). If $obj represents the number 123, then _digit($obj, 0) is 3 and _digit(123, -1) is 1. Return a true value if the object is OK, and a false value otherwise. This is a check routine to test the internal state of the object for corruption. Page 4

API version 2 Constructors The following methods are required for an API version of 2 or greater. _1ex(N) Mathematical functions Miscellaneous Return an object representing the number 10**N where N >= 0 is a Perl scalar. _nok(obj1, OBJ2) _alen(obj) API optional methods Return the binomial coefficient OBJ1 over OBJ1. Return the approximate number of decimal digits of the object. The output is one Perl scalar. This estimate must be greater than or equal to what _len() returns. The following methods are optional, and can be defined if the underlying lib has a fast way to do them. If undefined, Math::BigInt will use pure Perl (hence slow) fallback routines to emulate these: Signed bitwise operators. Each of these methods may modify the first input argument. _signed_or(obj1, OBJ2, SIGN1, SIGN2) Return the signed bitwise or. _signed_and(obj1, OBJ2, SIGN1, SIGN2) Return the signed bitwise and. _signed_xor(obj1, OBJ2, SIGN1, SIGN2) WRAP YOUR OWN Return the signed bitwise exclusive or. If you want to port your own favourite c-lib for big numbers to the Math::BigInt interface, you can take any of the already existing modules as a rough guideline. You should really wrap up the latest BigInt and BigFloat testsuites with your module, and replace in them any of the following: use Math::BigInt; by this: use Math::BigInt lib => 'yourlib'; BUGS SUPPORT This way you ensure that your library really works 100% within Math::BigInt. Please report any bugs or feature requests to bug-math-bigint at rt.cpan.org, or through the web interface at https://rt.cpan.org/ticket/create.html?queue=math-bigint (requires login). We will be notified, and then you'll automatically be notified of progress on your bug as I make changes. You can find documentation for this module with the perldoc command. perldoc Math::BigInt::Calc Page 5

You can also look for information at: LICENSE AUTHORS SEE ALSO * RT: CPAN's request tracker https://rt.cpan.org/public/dist/display.html?name=math-bigint * AnnoCPAN: Annotated CPAN documentation http://annocpan.org/dist/math-bigint * CPAN Ratings http://cpanratings.perl.org/dist/math-bigint * Search CPAN http://search.cpan.org/dist/math-bigint/ * CPAN Testers Matrix http://matrix.cpantesters.org/?dist=math-bigint * The Bignum mailing list * Post to mailing list bignum at lists.scsys.co.uk * View mailing list http://lists.scsys.co.uk/pipermail/bignum/ * Subscribe/Unsubscribe http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/bignum This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. Original math code by Mark Biggar, rewritten by Tels http://bloodgate.com/ in late 2000. Separated from BigInt and shaped API with the help of John Peacock. Fixed, speed-up, streamlined and enhanced by Tels 2001-2007. API documentation corrected and extended by Peter John Acklam, <pjacklam@online.no> Math::BigInt, Math::BigFloat, Math::BigInt::GMP, Math::BigInt::FastCalc and Math::BigInt::Pari. Page 6