1 /********************************************************************/ 2 /* */ 3 /* big_drv.h Driver functions for the bigInteger type. */ 4 /* Copyright (C) 1989 - 2014 Thomas Mertes */ 5 /* */ 6 /* This file is part of the Seed7 Runtime Library. */ 7 /* */ 8 /* The Seed7 Runtime Library is free software; you can */ 9 /* redistribute it and/or modify it under the terms of the GNU */ 10 /* Lesser General Public License as published by the Free Software */ 11 /* Foundation; either version 2.1 of the License, or (at your */ 12 /* option) any later version. */ 13 /* */ 14 /* The Seed7 Runtime Library is distributed in the hope that it */ 15 /* will be useful, but WITHOUT ANY WARRANTY; without even the */ 16 /* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */ 17 /* PURPOSE. See the GNU Lesser General Public License for more */ 18 /* details. */ 19 /* */ 20 /* You should have received a copy of the GNU Lesser General */ 21 /* Public License along with this program; if not, write to the */ 22 /* Free Software Foundation, Inc., 51 Franklin Street, */ 23 /* Fifth Floor, Boston, MA 02110-1301, USA. */ 24 /* */ 25 /* Module: Seed7 Runtime Library */ 26 /* File: seed7/src/big_drv.h */ 27 /* Changes: 2005, 2006, 2008 - 2010, 2013, 2014 Thomas Mertes */ 28 /* Content: Driver functions for the bigInteger type. */ 29 /* */ 30 /********************************************************************/ 31 32 #ifndef INT64TYPE 33 #define bigFromUInt64(x) 0 34 #define bigToInt64(x,e) 0 35 #endif 36 37 #if INTTYPE_SIZE == 64 38 #define bigIConv bigFromInt64 39 #define bigOrd(x) bigToInt64(x, NULL) 40 #elif INTTYPE_SIZE == 32 41 #define bigIConv bigFromInt32 42 #define bigOrd(x) bigToInt32(x, NULL) 43 #endif 44 45 46 void setupBig (void); 47 cstriType bigHexCStri (const const_bigIntType big1); 48 bigIntType bigAbs (const const_bigIntType big1); 49 bigIntType bigAbsTemp (bigIntType big1); 50 bigIntType bigAdd (const_bigIntType summand1, const_bigIntType summand2); 51 void bigAddAssign (bigIntType *const big_variable, const const_bigIntType delta); 52 void bigAddAssignSignedDigit (bigIntType *const big_variable, const intType delta); 53 bigIntType bigAddTemp (bigIntType summand1, const const_bigIntType summand2); 54 bigIntType bigAnd (const_bigIntType big1, const_bigIntType big2); 55 intType bigBitLength (const const_bigIntType big1); 56 intType bigCmp (const const_bigIntType big1, const const_bigIntType big2); 57 intType bigCmpSignedDigit (const const_bigIntType big1, intType number); 58 void bigCpy (bigIntType *const dest, const const_bigIntType source); 59 bigIntType bigCreate (const const_bigIntType source); 60 void bigDecr (bigIntType *const big_variable); 61 void bigDestr (const const_bigIntType old_bigint); 62 bigIntType bigDiv (const const_bigIntType dividend, const const_bigIntType divisor); 63 bigIntType bigDivRem (const const_bigIntType dividend, const const_bigIntType divisor, 64 bigIntType *remainderAddr); 65 boolType bigEq (const const_bigIntType big1, const const_bigIntType big2); 66 boolType bigEqSignedDigit (const const_bigIntType big1, intType number); 67 bigIntType bigFromByteBufferBe (const memSizeType size, 68 const const_ustriType buffer, const boolType isSigned); 69 bigIntType bigFromByteBufferLe (const memSizeType size, 70 const const_ustriType buffer, const boolType isSigned); 71 bigIntType bigFromBStriBe (const const_bstriType bstri, const boolType isSigned); 72 bigIntType bigFromBStriLe (const const_bstriType bstri, const boolType isSigned); 73 bigIntType bigFromInt32 (int32Type number); 74 #ifdef INT64TYPE 75 bigIntType bigFromInt64 (int64Type number); 76 #endif 77 bigIntType bigFromUInt32 (uint32Type number); 78 #ifdef INT64TYPE 79 bigIntType bigFromUInt64 (uint64Type number); 80 #endif 81 bigIntType bigGcd (const const_bigIntType big1, const const_bigIntType big2); 82 intType bigHashCode (const const_bigIntType big1); 83 void bigIncr (bigIntType *const big_variable); 84 bigIntType bigIPow (const const_bigIntType base, intType exponent); 85 bigIntType bigIPowSignedDigit (intType base, intType exponent); 86 bigIntType bigLog10 (const const_bigIntType big1); 87 bigIntType bigLog2 (const const_bigIntType big1); 88 bigIntType bigLowerBits (const const_bigIntType big1, const intType bits); 89 bigIntType bigLowerBitsTemp (const bigIntType big1, const intType bits); 90 uint64Type bigLowerBits64 (const const_bigIntType big1); 91 intType bigLowestSetBit (const const_bigIntType big1); 92 bigIntType bigLShift (const const_bigIntType big1, const intType lshift); 93 void bigLShiftAssign (bigIntType *const big_variable, intType lshift); 94 bigIntType bigLShiftOne (const intType lshift); 95 bigIntType bigLog2BaseIPow (const intType log2base, const intType exponent); 96 bigIntType bigMDiv (const const_bigIntType dividend, const const_bigIntType divisor); 97 bigIntType bigMod (const const_bigIntType dividend, const const_bigIntType divisor); 98 bigIntType bigMult (const_bigIntType factor1, const_bigIntType factor2); 99 void bigMultAssign (bigIntType *const big_variable, const_bigIntType factor); 100 bigIntType bigMultSignedDigit (const_bigIntType factor1, intType factor2); 101 bigIntType bigNegate (const const_bigIntType big1); 102 bigIntType bigNegateTemp (bigIntType big1); 103 boolType bigOdd (const const_bigIntType big1); 104 bigIntType bigOr (const_bigIntType big1, const_bigIntType big2); 105 bigIntType bigParse (const const_striType stri); 106 bigIntType bigParseBased (const const_striType stri, intType base); 107 bigIntType bigPred (const const_bigIntType big1); 108 bigIntType bigPredTemp (bigIntType big1); 109 striType bigRadix (const const_bigIntType big1, intType base, boolType upperCase); 110 bigIntType bigRand (const const_bigIntType low, const const_bigIntType high); 111 bigIntType bigRem (const const_bigIntType dividend, const const_bigIntType divisor); 112 bigIntType bigRShift (const const_bigIntType big1, const intType rshift); 113 void bigRShiftAssign (bigIntType *const big_variable, intType rshift); 114 bigIntType bigSbtr (const const_bigIntType minuend, const const_bigIntType subtrahend); 115 void bigSbtrAssign (bigIntType *const big_variable, const const_bigIntType delta); 116 bigIntType bigSbtrTemp (bigIntType minuend, const_bigIntType subtrahend); 117 bigIntType bigSquare (const_bigIntType big1); 118 striType bigStr (const const_bigIntType big1); 119 bigIntType bigSucc (const const_bigIntType big1); 120 bigIntType bigSuccTemp (bigIntType big1); 121 bstriType bigToBStriBe (const const_bigIntType big1, const boolType isSigned); 122 bstriType bigToBStriLe (const const_bigIntType big1, const boolType isSigned); 123 int16Type bigToInt16 (const const_bigIntType big1, errInfoType *err_info); 124 int32Type bigToInt32 (const const_bigIntType big1, errInfoType *err_info); 125 #ifdef INT64TYPE 126 int64Type bigToInt64 (const const_bigIntType big1, errInfoType *err_info); 127 uint64Type bigToUInt64 (const const_bigIntType big1); 128 #endif 129 bigIntType bigXor (const_bigIntType big1, const_bigIntType big2); 130 bigIntType bigZero (void); 131