1 /********************************************************************/
2 /*                                                                  */
3 /*  int_rtl.h     Primitive actions for the integer type.           */
4 /*  Copyright (C) 1989 - 2015  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/int_rtl.h                                       */
27 /*  Changes: 1992 - 1994, 2000, 2005, 2009 - 2015  Thomas Mertes    */
28 /*  Content: Primitive actions for the integer type.                */
29 /*                                                                  */
30 /********************************************************************/
31 
32 #if INTTYPE_SIZE == 32
33 #define RAND_MULTIPLIER           1103515245
34 #define RAND_INCREMENT                 12345
35 #elif INTTYPE_SIZE == 64
36 #define RAND_MULTIPLIER  6364136223846793005
37 #define RAND_INCREMENT   1442695040888963407
38 #endif
39 
40 extern const const_ustriType digitTable[];
41 
42 
43 void setupRand (void);
44 uintType uintMult (uintType factor1, uintType factor2, uintType *product_high);
45 striType uintNBytesBe (uintType number, intType length);
46 striType uintNBytesLe (uintType number, intType length);
47 uintType uintRand (void);
48 uintType uintRandMantissa (void);
49 uintType uintRandLimited (uintType rand_max);
50 int uint8MostSignificantBit (uint8Type number);
51 int uint16MostSignificantBit (uint16Type number);
52 int uint32MostSignificantBit (uint32Type number);
53 #ifdef INT64TYPE
54 int uint64MostSignificantBit (uint64Type number);
55 #endif
56 int uint8LeastSignificantBit (uint8Type number);
57 int uint16LeastSignificantBit (uint16Type number);
58 int uint32LeastSignificantBit (uint32Type number);
59 #ifdef INT64TYPE
60 int uint64LeastSignificantBit (uint64Type number);
61 #endif
62 intType uintCard (uintType number);
63 striType uintRadix (uintType number, intType base, boolType upperCase);
64 striType uintRadixPow2 (uintType number, int shift, int mask, boolType upperCase);
65 striType uintStr (uintType number);
66 intType intBinom (intType n_number, intType k_number);
67 uintType uintBinomNoChk (uintType n_number, intType k_number);
68 intType intBitLength (intType number);
69 striType intBytesBe (intType number, boolType isSigned);
70 intType intBytesBe2Int (const const_striType byteStri);
71 intType intBytesBe2UInt (const const_striType byteStri);
72 striType intBytesLe (intType number, boolType isSigned);
73 intType intBytesLe2Int (const const_striType byteStri);
74 intType intBytesLe2UInt (const const_striType byteStri);
75 intType intCmp (intType number1, intType number2);
76 intType intLog10 (intType number);
77 intType intLog2 (intType number);
78 intType intLowestSetBit (intType number);
79 striType intLpad0 (intType number, const intType padSize);
80 intType intMultOvfChk (intType factor1, intType factor2);
81 striType intNBytesBeSigned (intType number, intType length);
82 striType intNBytesBeUnsigned (intType number, intType length);
83 striType intNBytesLeSigned (intType number, intType length);
84 striType intNBytesLeUnsigned (intType number, intType length);
85 intType intParse (const const_striType stri);
86 intType intPow (intType base, intType exponent);
87 intType intPowOvfChk (intType base, intType exponent);
88 striType intRadix (intType number, intType base, boolType upperCase);
89 striType intRadixPow2 (intType number, int shift, int mask, boolType upperCase);
90 intType intRand (intType low, intType high);
91 intType intSqrt (intType number);
92 striType intStr (intType number);
93 #if ALLOW_STRITYPE_SLICES
94 striType intStrToBuffer (intType number, striType buffer);
95 #endif
96