LargeInteger.st
author Stefan Vogel <sv@exept.de>
Thu, 18 Nov 1999 17:10:32 +0100
changeset 5002 e895e251d501
parent 5000 46a73184be0d
child 5008 1a19e0059c54
permissions -rw-r--r--
__longIntVal has been renamed to __unsignedLongIntVal
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
345
claus
parents: 250
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
Integer subclass:#LargeInteger
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    14
	instanceVariableNames:'sign digitByteArray'
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    15
	classVariableNames:''
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    16
	poolDictionaries:''
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
    20
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
 COPYRIGHT (c) 1994 by Claus Gittinger
345
claus
parents: 250
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    36
documentation
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    37
"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    38
    This class provides arbitrary precision integers. These are represented as:
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    39
      sign (-1/0/+1) and, if sign ~~ 0
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    40
      a ByteArray of digits with 8 bits per element; 
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
      least significant 8 bits at index 1 ...
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    42
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    43
    The implementation is not completely tuned for high performance
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    44
    (more key-methods should be rewritten as primitives), although the
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    45
    common operations have been pretty tuned for some architectures.
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    46
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    47
    LargeIntegers are usually not created explicitely, but result from 
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    48
    SmallInteger arithmetic (overflowing the SmallInteger range).
357
claus
parents: 345
diff changeset
    49
    Also, results of LargeInteger operations are converted to back to 
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    50
    SmallIntegers, when possible (see #compressed).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    51
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    52
    In contrast to ST-80, there is only one class for LargeIntegers, keeping
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    53
    the sign as an instance variable (ST-80 has LargePositiveInteger and
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    54
    LargeNegativeInteger). This may change.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    55
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    56
    [author:]
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    57
        Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    58
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    59
    [see also:]
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    60
        Number
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    61
        Float Fraction FixedPoint 
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    62
        SmallInteger
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    63
"
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    64
!
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    65
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    66
testing
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    67
"
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    68
   test largeInt multiplication & division 
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    69
   (at least, test if they have not both errors which anull each other ;-)
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    70
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    71
   |last v|
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    72
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    73
   v := last := 1.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    74
   2 to:3000 do:[:i |
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    75
       i printCR.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    76
       v := v * i.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    77
       (v / i) ~= last ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
    78
	   self halt
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    79
       ].
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    80
       last := v.
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    81
   ]
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    82
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    83
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    84
   test addition, subtraction:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    85
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    86
   SmallInteger maxVal                -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    87
   SmallInteger maxVal + 1            -> 1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    88
   SmallInteger maxVal + 2            -> 1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    89
   (SmallInteger maxVal + 2) - 2      -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    90
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    91
   SmallInteger minVal                -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    92
   SmallInteger minVal - 1            -> -1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    93
   SmallInteger minVal - 2            -> -1073741826
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    94
   (SmallInteger minVal - 2) + 2      -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    95
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    96
   1234567890 + 10                    -> 1234567900
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    97
   1111111111 + 1111111111            -> 2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    98
   1111111111 - 1111111111            -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    99
   1111111111 - 2222222222            -> -1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   100
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   101
   1111111111 * 2                     -> 2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   102
   1111111111 * -2                    -> -2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   103
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   104
   1111111111 * 1111111111            -> 1234567900987654321
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   105
   1234567900987654321 // 1111111111  -> 1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   106
   1234567900987654321 \\ 1111111111  -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   107
   1234567900987654322 \\ 1111111111  -> 1
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   108
   1234567900987654421 \\ 1111111111  -> 100
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   109
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   110
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   111
   addition:
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   112
   (16rFFFFFFF0 + 1          ) hexPrintString -> 'FFFFFFF1'     
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   113
   (16rFFFFFFFF + 1          ) hexPrintString -> '100000000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   114
   (16rFFFFFFFF + 2          ) hexPrintString -> '100000001'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   115
   (16rFFFFFFFF + 16rFFFFFF  ) hexPrintString -> '100FFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   116
   (16rFFFFFFFF + 16rFFFFFFFF) hexPrintString -> '1FFFFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   117
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   118
   20 factorial         -> 2432902008176640000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   119
   20 factorial + 10000 -> 2432902008176650000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   120
   20 factorial               hexPrintString -> '21C3677C82B40000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   121
   (20 factorial + 16rFFFF)   hexPrintString -> '21C3677C82B4FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   122
   (20 factorial + 16rFFFFFF) hexPrintString -> '21C3677C83B3FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   123
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   124
   test comparison:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   125
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   126
   -1234567890 >  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   127
   -1234567890 >= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   128
   -1234567890 <  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   129
   -1234567890 <= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   130
   -1234567890 =  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   131
   -1234567890 ~= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   132
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   133
   -1234567890 >  -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   134
   -1234567890 >= -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   135
   -1234567890 <  -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   136
   -1234567890 <= -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   137
   -1234567890 =  -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   138
   -1234567890 ~= -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   139
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   140
   -1234567891 >  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   141
   -1234567891 >= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   142
   -1234567891 <  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   143
   -1234567891 <= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   144
   -1234567891 =  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   145
   -1234567891 ~= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   146
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   147
    1234567890 >  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   148
    1234567890 >= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   149
    1234567890 <  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   150
    1234567890 <= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   151
    1234567890 =  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   152
    1234567890 ~= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   153
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   154
   -1234567890 >  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   155
   -1234567890 >= 1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   156
   -1234567890 <  1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   157
   -1234567890 <= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   158
   -1234567890 =  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   159
   -1234567890 ~= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   160
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   161
    1234567890 >  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   162
    1234567890 >= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   163
    1234567890 <  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   164
    1234567890 <= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   165
    1234567890 =  1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   166
    1234567890 ~= 1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   167
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   168
   -1234567890 >  -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   169
   -1234567890 >= -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   170
   -1234567890 <  -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   171
   -1234567890 <= -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   172
   -1234567890 =  -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   173
   -1234567890 ~= -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   174
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   175
   -1234567890 >  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   176
   -1234567890 >= 10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   177
   -1234567890 <  10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   178
   -1234567890 <= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   179
   -1234567890 =  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   180
   -1234567890 ~= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   181
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   182
   -10 >  -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   183
   -10 >= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   184
   -10 <  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   185
   -10 <= -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   186
   -10 =  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   187
   -10 ~= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   188
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   189
    10 >  -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   190
    10 >= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   191
    10 <  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   192
    10 <= -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   193
    10 =  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   194
    10 ~= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   195
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   196
    1234567890 >  -10                 true  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   197
    1234567890 >= -10                 true  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   198
    1234567890 <  -10                 false  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   199
    1234567890 <= -10                 false  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   200
    1234567890 =  -10                 false  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   201
    1234567890 ~= -10                 true  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   202
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   203
    1234567890 >  10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   204
    1234567890 >= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   205
    1234567890 <  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   206
    1234567890 <= 10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   207
    1234567890 =  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   208
    1234567890 ~= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   209
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   210
   -10 >   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   211
   -10 >=  1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   212
   -10 <   1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   213
   -10 <=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   214
   -10 =   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   215
   -10 ~=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   216
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   217
    10 >   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   218
    10 >=  1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   219
    10 <   1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   220
    10 <=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   221
    10 =   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   222
    10 ~=  1234567890                 true
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
   223
"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   224
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   225
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   226
!LargeInteger class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   227
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   228
digitBytes:aByteArrayOfDigits
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   229
    "create and return a new LargeInteger with digits (lsb-first)
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   230
     from the argument, aByteArray.
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   231
     Experimental interface - May change/be removed without notice."
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   232
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   233
    ^ self basicNew setDigits:aByteArrayOfDigits
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   234
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   235
    "
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   236
     LargeInteger digitBytes:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]
4806
1b48e7420cfe comment
Claus Gittinger <cg@exept.de>
parents: 4794
diff changeset
   237
     (LargeInteger digitBytes:#[16r12 16r34 16r56 16r78 16r90]) hexPrintString
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   238
    "
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   239
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   240
    "Modified: / 8.5.1998 / 21:40:41 / cg"
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   241
!
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   242
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   243
new
4299
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   244
    "catch creation message.
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   245
     LargeIntegers are only created by system code, which 
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   246
     uses basicNew and cares for correct initialization."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   247
a27a279701f8 Initial revision
claus
parents:
diff changeset
   248
    self error:'LargeIntegers cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
   249
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   250
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   251
new:numberOfDigits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   252
    "catch creation message"
2
claus
parents: 1
diff changeset
   253
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   254
    self error:'LargeIntegers cannot be created with new'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   255
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   256
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   257
value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   258
    "create and return a new LargeInteger with value taken from
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   259
     the argument, aSmallInteger.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   260
     Notice: 
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   261
	this should be only used internally, since such small
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   262
	largeIntegers do not normally occur in the system.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   263
	(They are used by myself)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   264
     May change/be removed without notice."
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   265
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   266
    ^ self basicNew value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   267
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   268
    "LargeInteger value:3689"
3438
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   269
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   270
    "Modified: / 8.5.1998 / 21:40:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   271
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   272
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   273
!LargeInteger class methodsFor:'queries'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   274
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   275
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   276
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   277
     Here, true is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   278
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   279
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   280
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   281
    "Modified: 23.4.1996 / 15:59:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   282
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   283
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   284
!LargeInteger methodsFor:'arithmetic'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   285
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   286
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   288
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   289
    |otherSign numberClass|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   290
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   291
    (sign == 0) ifTrue:[^ 0].  "cannot happen if correctly normalized"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   292
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   293
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   294
     this is the common case, multiplying with SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   295
     Use a special method for this case ...
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   297
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   298
	^ self productFromInteger:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
     if the argument is not a largeInteger, coerce
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   304
    (numberClass == self class) ifFalse:[
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
	^ self retry:#* coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   306
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   309
    (sign == otherSign) ifTrue:[^ self absMul:aNumber].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   310
    (otherSign == 0) ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   311
    ^ (self absMul:aNumber) sign:-1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   312
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   314
+ aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   315
    "return the sum of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   316
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   317
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   318
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   319
    (sign == 0) ifTrue:[^ aNumber].  "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   320
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   321
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   322
     this is the common case, adding a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   323
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   324
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   325
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   326
	^ self sumFromInteger:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   327
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   328
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   329
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   330
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   331
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   332
    (numberClass == self class) ifFalse:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   333
	^ self retry:#+ coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   334
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   335
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   336
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   337
    (sign > 0) ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   338
	"I am positive"
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   339
	(otherSign > 0) ifTrue:[^ self absPlus:aNumber sign:1].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   340
	(otherSign < 0) ifTrue:[^ self absMinus:aNumber sign:1].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   341
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   342
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   343
    "I am negative"
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
   344
    (otherSign > 0) ifTrue:[^ aNumber absMinus:self sign:1].
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
   345
    (otherSign < 0) ifTrue:[^ self absPlus:aNumber sign:-1].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   346
    ^ self
357
claus
parents: 345
diff changeset
   347
claus
parents: 345
diff changeset
   348
    "
claus
parents: 345
diff changeset
   349
     SmallInteger maxVal 
claus
parents: 345
diff changeset
   350
     SmallInteger maxVal + 1  
claus
parents: 345
diff changeset
   351
     SmallInteger maxVal + 2 
claus
parents: 345
diff changeset
   352
     SmallInteger minVal    
claus
parents: 345
diff changeset
   353
     SmallInteger minVal - 1
claus
parents: 345
diff changeset
   354
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   355
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   356
    "Modified: / 9.1.1998 / 13:26:28 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   357
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   358
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   359
- aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   360
    "return the difference of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   361
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   362
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   363
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   364
    (sign == 0) ifTrue:[^ aNumber negated].     "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   365
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   366
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   367
     this is the common case, subtracting a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   368
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   369
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   370
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   371
        sign > 0 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   372
            aNumber > 0 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   373
                ^ self absFastMinus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   374
            ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   375
            ^ self absFastPlus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   376
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   377
        aNumber > 0 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   378
            ^ self absFastPlus:aNumber sign:-1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   379
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   380
        ^ self absFastMinus:aNumber sign:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   381
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   382
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   383
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   384
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   385
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   386
    (numberClass == self class) ifFalse:[
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   387
        ^ self retry:#- coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   388
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   389
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   390
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   391
    (sign > 0) ifTrue:[
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   392
        "I am positive"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   393
        (otherSign > 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   394
            "+large - +large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   395
            ^ self absMinus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   396
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   397
        (otherSign < 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   398
            "+large - -large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   399
            ^ self absPlus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   400
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   401
        "should not happen"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   402
        ^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   403
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   404
    "I am negative"
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   405
    (otherSign > 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   406
        "-large - +large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   407
        ^ self absPlus:aNumber sign:-1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   408
    ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   409
    (otherSign < 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   410
        "-large - -large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   411
        ^ self absMinus:aNumber sign:-1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   412
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   413
    ^ self
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   414
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   415
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   416
     12345678901234567890 - 0     
357
claus
parents: 345
diff changeset
   417
     12345678901234567890 - 1      
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   418
     12345678901234567890 - -1    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   419
     -12345678901234567890 - 1     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   420
     -12345678901234567890 - -1    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   421
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   422
     12345678901234567890 - 12345678901234567880     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   423
     12345678901234567890 - 12345000000000000000     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   424
     12345678901234567890 - -87654321098765432110    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   425
     -12345678901234567890 - 87654321098765432110    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   426
     -12345678901234567890 - -12345678901234567880   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   427
     -12345678901234567890 - -12345678901234567980   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   428
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   429
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   430
    "Modified: 20.10.1996 / 18:42:16 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   431
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   432
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   433
/ aNumber
1065
77b25fb9f9d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   434
    "return the quotient of the receiver and the argument, aNumber"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   435
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   436
    aNumber isInteger ifTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   437
	^ Fraction numerator:self
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   438
		  denominator:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   439
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   440
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   441
    "this is a q&d hack - we loose lots of precision here ..."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   442
    ^ (self asFloat / aNumber asFloat)
2793
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   443
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   444
    "Modified: 28.7.1997 / 19:07:55 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   445
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   446
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   447
// aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   448
    "return the quotient of the receiver and the argument, aNumber.
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   449
     The result is truncated toward negative infinity and negative,
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   450
     if the operands signs differ."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   451
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   452
    |cls divMod quo abs "{ Class: SmallInteger }" n|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   453
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   454
    cls := aNumber class.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   455
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   456
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   457
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   458
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   459
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   460
    (cls == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   461
	abs := aNumber.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   462
	abs := abs abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   463
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   464
	    divMod := self absFastDivMod:abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   465
	] ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   466
	    n := abs asLargeInteger.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   467
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   468
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   469
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   470
	 if the argument is not a largeInteger, coerce
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   471
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   472
	(cls == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   473
	    ^ self retry:#// coercing:aNumber
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   474
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   475
	n := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   476
    ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   477
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   478
    divMod isNil ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   479
	divMod := self absDivMod:n.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   480
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   481
    quo := divMod at:1.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   482
    (sign == aNumber sign) ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   483
	"/ adjust for truncation if negative and there is a remainder ...
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   484
	quo := quo sign:-1.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   485
	(divMod at:2) == 0 ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   486
	    ^ quo - 1
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   487
	].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   488
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   489
    ^ quo
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   490
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   491
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   492
     (9000000000 // 4000000000)   =   (900 // 400)   ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   493
     (-9000000000 // 4000000000)  =   (-900 // 400)  ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   494
     (9000000000 // -4000000000)  =   (900 // -400)  ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   495
     (-9000000000 // -4000000000) =   (-900 // -400) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   496
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   497
     16rfffffffff // 16r01ffffff  =   2048 ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   498
     16rfffffffff // 16r00ffffff  =   4096 ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   499
     16rfffffffff // 16r001fffff  =  32768 ifFalse:[self halt].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   500
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   501
     900 quo: 400   
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   502
     -900 quo: 400                   
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   503
     900 quo: -400                   
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   504
     -900 quo: -400 
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   505
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   506
     9000000000 quo: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   507
     -9000000000 quo: 4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   508
     9000000000 quo: -4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   509
     -9000000000 quo: -4000000000 
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   510
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   511
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   512
    "Modified: / 5.11.1996 / 16:39:36 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   513
    "Modified: / 27.4.1999 / 19:50:26 / stefan"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   514
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   515
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   516
\\ aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   517
    "Answer the integer remainder m defined by division with truncation toward
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   518
     negative infinity. The remainder has the same sign as aNumber.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   519
     m < |aNumber| AND there is an integer k with (k * aNumber + m) = self
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   520
     Compare with #rem:"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   521
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   522
    |abs rem negativeDivisor|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   523
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   524
    aNumber negative ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   525
	negativeDivisor := true.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   526
	abs := aNumber negated.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   527
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   528
	negativeDivisor := false.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   529
	abs := aNumber.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   530
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   531
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   532
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   533
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   534
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   535
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   536
    (aNumber class == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   537
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   538
	    rem := (self absFastDivMod:abs) at:2.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   539
	] ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   540
	    rem := self absMod:abs asLargeInteger
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   541
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   542
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   543
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   544
	 if the argument is not a largeInteger, coerce
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   545
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   546
	(aNumber class == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   547
	    ^ self retry:#\\ coercing:aNumber
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   548
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   549
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   550
	rem := self absMod:abs.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   551
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   552
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   553
    rem = 0 ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   554
	negativeDivisor ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   555
	    rem := rem sign:-1
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   556
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   557
	(self negative ~~ negativeDivisor) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   558
	    "different sign, so remainder would have been negative.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   559
	     rem has been rounded toward zero, this code will simulate
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   560
	     rounding to negative infinity."
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   561
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   562
	    rem := aNumber - rem.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   563
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   564
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   565
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   566
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   567
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   568
     (9000000000 \\ 4000000000)   = (900 \\ 400 * 10000000)  ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   569
     (-9000000000 \\ 4000000000)  = (-900 \\ 400 * 10000000) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   570
     (9000000000 \\ -4000000000)  = (900 \\ -400 * 10000000) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   571
     (-9000000000 \\ -4000000000) = (-900 \\ -400 * 10000000)ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   572
     (16000000000 \\ 4000000000)  = (1600 \\ 400 * 10000000) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   573
     (-16000000000 \\ 4000000000)  = (-1600 \\ 400 * 10000000) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   574
     (16000000000 \\ -4000000000)  = (1600 \\ -400 * 10000000) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   575
     (-16000000000 \\ -4000000000)  = (-1600 \\ -400 * 10000000) ifFalse:[self halt].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   576
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   577
     9000000000 \\ 7      
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   578
     -9000000000 \\ 7     
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   579
     9000000000 \\ -7     
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   580
     -9000000000 \\ -7    
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   581
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   582
     900 rem: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   583
     -900 rem: 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   584
     900 rem: -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   585
     -900 rem: -400               
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   586
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   587
     9000000000 rem: 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   588
     -9000000000 rem: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   589
     9000000000 rem: -4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   590
     -9000000000 rem: -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   591
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   592
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   593
    "Modified: / 5.11.1996 / 17:10:10 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   594
    "Modified: / 27.4.1999 / 20:03:40 / stefan"
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   595
!
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   596
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   597
abs
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   598
    "return my absolute value. redefined for speed."
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   599
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   600
    sign >= 0 ifTrue:[^ self].
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   601
    ^ self negated
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   602
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   603
    "Created: / 26.10.1999 / 21:28:06 / stefan"
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   604
!
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   605
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   606
divMod:aNumber
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   607
    "return an array filled with self // aNumber and
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   608
     self \\ aNumber.
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   609
     The result is only defined for positive receiver and
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   610
     argument."
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   611
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   612
    |cls n|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   613
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   614
    cls := aNumber class.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   615
    (cls == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   616
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   617
	 this is the common case, dividing by a SmallInteger.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   618
	 Use a special method for this case ...
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   619
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   620
	(aNumber between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   621
	    ^ self absFastDivMod:aNumber abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   622
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   623
	n := aNumber asLargeInteger.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   624
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   625
	(cls == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   626
	    ^ super divMod:aNumber            
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   627
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   628
	n := aNumber.
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   629
    ].
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   630
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   631
    ^ self absDivMod:n abs
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   632
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   633
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   634
     9000000000 // 4000000000   => 2
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   635
     9000000000 \\ 4000000000   => 1000000000 
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   636
     9000000000 divMod: 4000000000   => #(2 1000000000)
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   637
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   638
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   639
    "Created: / 29.10.1996 / 21:22:05 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   640
    "Modified: / 27.4.1999 / 19:48:58 / stefan"
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   641
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   642
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   643
negated
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   644
    "return an integer with value negated from the receivers value."
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   645
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   646
    |newNumber sz|
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   647
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   648
    (sign == 0) ifTrue:[^ 0].
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   649
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   650
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   651
     special case for SmallInteger minVal
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   652
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   653
    sign == 1 ifTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   654
	sz := digitByteArray size.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   655
%{
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   656
	int idx;
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   657
	unsigned char *bp;
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   658
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   659
	bp = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   660
	idx = __intVal(sz);
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   661
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   662
	while ((idx > 1) && (bp[idx-1] == 0)) idx--;
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   663
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   664
	if (idx == sizeof(INT)) {
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   665
#if defined(alpha64)
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   666
	    if ( ((unsigned INT *)bp)[0] == 0x4000000000000000L)
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   667
#else
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   668
# if defined(i386) /* actually: LSBFIRST */
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   669
	    if ( ((unsigned INT *)bp)[0] == 0x40000000)
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   670
# else
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   671
	    /*
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   672
	     * generic code
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   673
	     */
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   674
	    if ((bp[idx-1] == 0x40)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   675
	     && (bp[idx-2] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   676
	     && (bp[idx-3] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   677
	     && (bp[idx-4] == 0)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   678
#  ifdef alpha64
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   679
	     && (bp[idx-5] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   680
	     && (bp[idx-6] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   681
	     && (bp[idx-7] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   682
	     && (bp[idx-8] == 0)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   683
#  endif
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   684
	    ) 
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   685
# endif
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   686
#endif
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   687
	    {
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   688
		RETURN (__MKSMALLINT(_MIN_INT));
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   689
	    }
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   690
	}
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   691
%}.
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   692
"/      sz == 4 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   693
"/        (digitByteArray at:1) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   694
"/          (digitByteArray at:2) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   695
"/            (digitByteArray at:3) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   696
"/              (digitByteArray at:4) == 16r40 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   697
"/                ^ SmallInteger minVal
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   698
"/              ].
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   699
"/            ]
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   700
"/          ]
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   701
"/        ]
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   702
"/      ]
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   703
    ].
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   704
    newNumber := self shallowCopy.
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   705
    newNumber sign:(sign negated).
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   706
    ^ newNumber
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   707
!
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   708
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   709
quo:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   710
    "return the quotient of the receiver and the argument, aNumber.
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   711
     The result is truncated toward zero (which is different from //, which
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   712
     truncates toward negative infinity).
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   713
     The results sign is negative if the receiver has a sign
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   714
     different from the args sign"
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   715
2521
43b9d4fafb35 removed unused locals
Claus Gittinger <cg@exept.de>
parents: 2495
diff changeset
   716
    |otherSign quo abs "{ Class: SmallInteger }" |
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   717
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   718
    otherSign := aNumber sign.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   719
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   720
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   721
     this is the common case, dividing by a SmallInteger.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   722
     Use a special method for this case ...
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   723
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   724
    (aNumber class == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   725
	abs := aNumber.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   726
	abs := abs abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   727
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   728
	    quo := (self absFastDivMod:abs) at:1.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   729
	    (sign == otherSign) ifTrue:[^ quo].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   730
	    ^ quo sign:-1
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   731
	]
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   732
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   733
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   734
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   735
     if the argument is not a largeInteger, coerce
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   736
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   737
    (aNumber class == self class) ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   738
	^ self retry:#quo: coercing:aNumber
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   739
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   740
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   741
    sign < 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   742
	(sign == otherSign) ifTrue:[^ (self absDivMod:aNumber negated) at:1].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   743
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   744
	(sign == otherSign) ifTrue:[^ (self absDivMod:aNumber) at:1].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   745
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   746
    ^ ((self absDivMod:aNumber) at:1) sign:-1
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   747
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   748
    "
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   749
     900 // 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   750
     -900 // 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   751
     900 // -400 
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   752
     -900 // -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   753
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   754
     9000000000 // 4000000000     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   755
     -9000000000 // 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   756
     9000000000 // -4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   757
     -9000000000 // -4000000000   
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   758
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   759
     900 quo: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   760
     -900 quo: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   761
     900 quo: -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   762
     -900 quo: -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   763
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   764
     9000000000 quo: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   765
     -9000000000 quo: 4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   766
     9000000000 quo: -4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   767
     -9000000000 quo: -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   768
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   769
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   770
    "Modified: / 5.11.1996 / 14:14:17 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   771
    "Modified: / 27.4.1999 / 20:01:22 / stefan"
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   772
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   773
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   774
rem:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   775
    "return the remainder of division of the receiver by the argument, aNumber.
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   776
     The returned remainder has the same sign as the receiver."
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   777
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   778
    |rem abs "{ Class: SmallInteger }" |
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   779
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   780
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   781
     this is the common case, dividing by a SmallInteger.
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   782
     Use special code for this case ...
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   783
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   784
    (aNumber class == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   785
	abs := aNumber.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   786
	abs := abs abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   787
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   788
	    rem := (self absFastDivMod:abs) at:2.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   789
	] ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   790
	    rem := self absMod:abs asLargeInteger
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   791
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   792
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   793
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   794
	 if the argument is not a largeInteger, coerce
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   795
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   796
	(aNumber class == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   797
	    ^ self retry:#rem coercing:aNumber
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   798
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   799
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   800
	rem := self absMod:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   801
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   802
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   803
    sign < 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   804
	^ rem sign:-1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   805
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   806
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   807
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   808
    "
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   809
     900 \\ 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   810
     -900 \\ 400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   811
     900 \\ -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   812
     -900 \\ -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   813
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   814
     9000000000 \\ 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   815
     -9000000000 \\ 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   816
     9000000000 \\ -4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   817
     -9000000000 \\ -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   818
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   819
     900 rem: 400     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   820
     -900 rem: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   821
     900 rem: -400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   822
     -900 rem: -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   823
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   824
     9000000000 rem: 4000000000     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   825
     -9000000000 rem: 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   826
     9000000000 rem: -4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   827
     -9000000000 rem: -4000000000   
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   828
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   829
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   830
    "Modified: / 5.11.1996 / 14:02:59 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   831
    "Modified: / 29.4.1999 / 11:26:51 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   832
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   833
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   834
!LargeInteger methodsFor:'bit operators'!
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   835
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   836
bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   837
    "return the bitwise-and of the receiver and the argument, anInteger"
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   838
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   839
%{  /* NOCONTEXT */
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   840
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   841
    if (__isSmallInteger(anInteger)) {
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   842
        INT v2 = __intVal(anInteger);
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   843
        INT v1;
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   844
#if defined(__LSBFIRST) || defined(i386)
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   845
        v1 = *(INT *)(__stringVal(__INST(digitByteArray)));
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   846
#else
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   847
        unsigned char *digits = (unsigned char *)(__stringVal(__INST(digitByteArray)));
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   848
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   849
        v1 = digits[0] & 0xFF;
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   850
        v1 = v1 | ((digits[1] & 0xFF)<<8);
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   851
        v1 = v1 | ((digits[2] & 0xFF)<<16);
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   852
        v1 = v1 | ((digits[3] & 0xFF)<<24);
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   853
#endif
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   854
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   855
        RETURN ( __MKSMALLINT(v1 & v2) );
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   856
    }
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   857
%}.
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   858
    ^ super bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   859
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   860
    "
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   861
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFF) 
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   862
    "
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   863
!
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   864
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   865
bitXor:anInteger
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   866
    "return the bitwise-or of the receiver and the argument, anInteger.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   867
     Here, a specially tuned version for largeInteger arguments 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   868
     (to speed up some cryptographic code)"
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   869
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   870
    |n "{ Class: SmallInteger }"
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   871
     len1 len2 result byte newBytes|
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   872
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   873
    anInteger class ~~ LargeInteger ifTrue:[^ super bitXor:anInteger].
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   874
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   875
    (len1 := anInteger digitLength) > (len2 := self digitLength) ifTrue:[
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   876
        newBytes := anInteger digits copy.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   877
        newBytes bitXorBytesFrom:1 to:len2 with:digitByteArray startingAt:1 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   878
    ] ifFalse:[
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   879
        newBytes := digitByteArray copy.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   880
        newBytes bitXorBytesFrom:1 to:len1 with:anInteger digits startingAt:1 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   881
    ].
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   882
    ^ (LargeInteger digitBytes:newBytes) compressed
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   883
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   884
    "
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   885
     (16r112233445566778899 bitXor:16rFF                ) printStringRadix:16 '112233445566778866' 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   886
     (16r112233445566778899 bitXor:16rFFFFFFFFFFFFFFFF00) printStringRadix:16 'EEDDCCBBAA99887799'
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   887
     (16r112233445566778899 bitXor:16rFF0000000000000000) printStringRadix:16 'EE2233445566778899'
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   888
     (16r112233445566778899 bitXor:16r112233445566778800) printStringRadix:16 '99' 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   889
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   890
     |bigNum1 bigNum2|
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   891
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   892
     bigNum1 := 2 raisedToInteger:512.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   893
     bigNum2 := 2 raisedToInteger:510.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   894
     Time millisecondsToRun:[
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   895
        1000000 timesRepeat:[
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   896
           bigNum1 bitXor:bigNum2.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   897
        ]
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   898
     ]      
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   899
    "
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   900
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   901
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   902
!
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   903
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   904
lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   905
    "return the bitIndex of the lowest bit set. The returned bitIndex
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   906
     starts at 1 for the least significant bit. Returns -1 if no bit is set.
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   907
     For negative numbers, the low bit of my absolute value is returned.
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   908
     Redefined here for more performance of the gcd: algorithm, which
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   909
     is used when big fractions are reduced."
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   910
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   911
    |sz "{ Class: SmallInteger }"
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   912
     byte|
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   913
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   914
    sz := digitByteArray size.
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   915
    1 to:sz do:[:digitIndex |
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   916
	(byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   917
	    ^ (digitIndex-1)*8 + byte lowBit
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   918
	]
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   919
    ].
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   920
    ^ -1
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   921
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   922
    "
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   923
     (1 bitShift:30) lowBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   924
     (1 bitShift:30) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   925
     (1 bitShift:31) lowBit   
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   926
     (1 bitShift:31) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   927
     (1 bitShift:32) lowBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   928
     (1 bitShift:32) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   929
     (1 bitShift:33) lowBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   930
     (1 bitShift:33) highBit 
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   931
     (1 bitShift:64) lowBit 
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   932
     (1 bitShift:64) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   933
     (1 bitShift:1000) lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   934
     (1 bitShift:1000) highBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   935
     ((1 bitShift:64)-1) lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   936
     ((1 bitShift:64)-1) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   937
    "
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   938
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   939
    "Modified: 14.8.1997 / 11:55:34 / cg"
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   940
! !
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   941
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   942
!LargeInteger methodsFor:'byte access'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   943
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   944
digitAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   945
    "return 8 bits of value, starting at byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   946
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   947
    index > digitByteArray size ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   948
    ^ digitByteArray at:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   949
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   950
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   951
digitAt:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   952
    "set the 8 bits, index is a byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   953
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   954
    digitByteArray at:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   955
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   956
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   957
digitByteAt:index
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   958
    "return 8 bits of my signed value, starting at byte index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   959
     For positive receivers, this is the same as #digitAt:;
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   960
     for negative ones, the actual bit representation is returned."
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   961
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   962
    |t digits|
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   963
    sign < 0 ifFalse:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   964
        index > digitByteArray size ifTrue:[
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   965
            ^ 0
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   966
        ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   967
        ^ digitByteArray at:index.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   968
    ].
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   969
    "/ negative int - do 2's complement here
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   970
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   971
    t := self bitInvert + 1.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   972
    t sign:1.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   973
    digits := t digitBytes.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   974
    index > digits size ifTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   975
        ^ 16rFF
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   976
    ].
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   977
    ^ digits at:index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   978
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   979
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   980
     16r11111111111111111111 negated digitByteAt:1
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   981
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   982
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   983
    "Created: / 25.10.1998 / 14:12:21 / cg"
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   984
!
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   985
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   986
digitBytes
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   987
    "return a byteArray filled with the receivers bits
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   988
     (8 bits of the absolute value per element).
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   989
     Least significant byte is first!!"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   990
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   991
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   992
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   993
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   994
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   995
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   996
digitBytesMSB:msbFlag
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   997
    "return a byteArray filled with the receivers bits
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   998
     (8 bits of the absolute value per element),
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   999
     if msbflag = true, most significant byte is first,
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1000
     otherwise least significant byte is first"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1001
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1002
    msbFlag ifTrue:[
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1003
        ^ digitByteArray copyReverse.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1004
    ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1005
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1006
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1007
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1008
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1009
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1010
digitLength
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1011
    "return the number bytes used by this Integer.
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1012
     For negative receivers, the digitLength of its absolute value
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1013
     is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1014
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1015
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1016
     check if there is a 0-byte ...
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1017
     this allows to ask unnormalized LargeIntegers 
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1018
     for their digitLength
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1019
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1020
    |l "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1021
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1022
    l := digitByteArray size.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1023
    [l ~~ 0 and:[(digitByteArray at:l) == 0]] whileTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1024
	l := l - 1.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1025
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1026
    ^ l
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1027
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1028
    "Modified: 31.7.1997 / 13:18:28 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1029
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1030
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1031
digits
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1032
    "obsolete,use #digitBytes"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1033
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1034
    ^ digitByteArray
4151
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
  1035
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
  1036
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1037
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1038
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1039
!LargeInteger methodsFor:'coercing & converting'!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1040
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1041
asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1042
    "return a Float with same value as myself.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1043
     Since floats have a limited precision, you usually loose bits when
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1044
     doing this."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1045
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1046
    |newFloat|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1047
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1048
    newFloat := 0.0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1049
    (sign == 0) ifFalse:[
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1050
        digitByteArray reverseDo:[:aDigit |
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1051
            newFloat := (newFloat * 256.0) + aDigit asFloat
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1052
        ].
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1053
        (sign < 0) ifTrue:[
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1054
            newFloat := newFloat negated
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1055
        ]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1056
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1057
    ^ newFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1058
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1059
    "
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1060
     1234567890 asFloat                     
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1061
     1234567890 asFloat asInteger                    
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1062
     12345678901234567890 asFloat           
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1063
     12345678901234567890 asFloat asInteger   
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1064
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1065
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1066
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1067
asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1068
    "return a LargeInteger with same value as myself - thats me"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1069
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1070
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1071
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1072
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1073
asSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1074
    "return a SmallInteger with same value as myself - 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1075
     the result is invalid if the receivers value cannot 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1076
     be represented as a SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1077
     Q: should we raise an exception if this happens ?"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1078
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1079
    |value|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1080
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1081
    value := 0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1082
    (sign == 0) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1083
	digitByteArray reverseDo:[:aDigit |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1084
	    value := (value times:256) + aDigit 
345
claus
parents: 250
diff changeset
  1085
	].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1086
	(sign < 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1087
	    value := value negated
345
claus
parents: 250
diff changeset
  1088
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1089
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1090
    ^ value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1091
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1092
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1093
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1094
    "return the argument as a LargeInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1095
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1096
    ^ aNumber asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1097
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1098
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1099
compressed
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1100
    "if the receiver can be represented as a SmallInteger, return
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1101
     a SmallInteger with my value; 
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1102
     otherwise remove leading zero bytes in the digitByte array
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1103
     and return the receiver"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1104
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1105
    |index "{ Class: SmallInteger }" 
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1106
     val   "{ Class: SmallInteger }" 
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1107
     index0
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1108
    |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1109
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1110
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1111
    OBJ t;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1112
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1113
    if (__INST(sign) == __MKSMALLINT(0)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1114
        RETURN (__MKSMALLINT(0));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1115
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1116
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1117
    t = __INST(digitByteArray);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1118
    if (__isByteArray(t)) {
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1119
        unsigned char *__digitBytes = __ByteArrayInstPtr(t)->ba_element;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1120
        int _idx, _idx0;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1121
        INT _val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1122
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1123
        _idx = _idx0 = __byteArraySize(t);
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1124
        while ((_idx > 0) && (__digitBytes[_idx - 1] == 0)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1125
            _idx--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1126
        }
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
  1127
#ifdef alpha64
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1128
        switch (_idx) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1129
            case 8:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1130
                _val = __digitBytes[7];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1131
                if (_val <= 0x40) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1132
                    _val = (_val<<8);
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1133
                    _val = (_val + __digitBytes[6]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1134
                    _val = (_val + __digitBytes[5]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1135
                    _val = (_val + __digitBytes[4]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1136
                    _val = (_val + __digitBytes[3]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1137
                    _val = (_val + __digitBytes[2]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1138
                    _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1139
                    _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1140
                    if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1141
                        _val = -_val;
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1142
                    if (__ISVALIDINTEGER(_val)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1143
                        RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1144
                    }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1145
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1146
                break;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1147
            case 7:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1148
                _val = (__digitBytes[6]<<8);
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1149
                _val = (_val + __digitBytes[5]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1150
                _val = (_val + __digitBytes[4]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1151
                _val = (_val + __digitBytes[3]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1152
                _val = (_val + __digitBytes[2]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1153
                _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1154
                _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1155
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1156
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1157
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1158
            case 6:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1159
                _val = (__digitBytes[5]<<8);
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1160
                _val = (_val + __digitBytes[4]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1161
                _val = (_val + __digitBytes[3]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1162
                _val = (_val + __digitBytes[2]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1163
                _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1164
                _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1165
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1166
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1167
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1168
            case 5:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1169
                _val = (__digitBytes[4]<<8);
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1170
                _val = (_val + __digitBytes[3]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1171
                _val = (_val + __digitBytes[2]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1172
                _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1173
                _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1174
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1175
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1176
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1177
            case 4:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1178
                _val = (__digitBytes[3]<<8);
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1179
                _val = (_val + __digitBytes[2]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1180
                _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1181
                _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1182
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1183
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1184
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1185
            case 3:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1186
                _val = (__digitBytes[2]<<8);
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1187
                _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1188
                _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1189
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1190
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1191
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1192
            case 2:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1193
                _val = (__digitBytes[1]<<8) + __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1194
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1195
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1196
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1197
            case 1:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1198
                _val = __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1199
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1200
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1201
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1202
            case 0:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1203
                RETURN (__MKSMALLINT(0));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1204
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1205
        }
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1206
#else
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1207
        if (_idx <= 4) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1208
            if (_idx <= 2) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1209
                if (_idx == 0) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1210
                    RETURN (__MKSMALLINT(0));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1211
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1212
                if (_idx == 1) {
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1213
                    _val = __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1214
                    if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1215
                        _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1216
                    RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1217
                }
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1218
                _val = (__digitBytes[1]<<8) + __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1219
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1220
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1221
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1222
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1223
            if (_idx == 3) {
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1224
                _val = (((__digitBytes[2]<<8) + __digitBytes[1])<<8) + __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1225
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1226
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1227
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1228
            }
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1229
            _val = __digitBytes[3];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1230
            if (_val <= 0x40) {
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1231
                _val = (((((_val<<8) + __digitBytes[2])<<8) + __digitBytes[1])<<8) + __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1232
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1233
                    _val = -_val;
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1234
                if (__ISVALIDINTEGER(_val)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1235
                    RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1236
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1237
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1238
        }
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1239
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1240
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1241
        if (_idx == _idx0) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1242
            RETURN (self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1243
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1244
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1245
        /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1246
         * must copy & cut off some bytes
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1247
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1248
        {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1249
            OBJ newDigits;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1250
            OBJ oldDigits;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1251
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1252
            /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1253
             * careful - there is no context here to protect
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1254
             * the receiver ...
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1255
             */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1256
            __PROTECT__(self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1257
            __PROTECT__(__INST(digitByteArray));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1258
            newDigits = __BYTEARRAY_UNINITIALIZED_NEW_INT(_idx);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1259
            __UNPROTECT__(oldDigits);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1260
            __UNPROTECT__(self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1261
            if (newDigits) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1262
                bcopy(__ByteArrayInstPtr(oldDigits)->ba_element,
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1263
                      __ByteArrayInstPtr(newDigits)->ba_element,
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1264
                      _idx);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1265
                __INST(digitByteArray) = newDigits; __STORE(self, newDigits);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1266
                RETURN (self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1267
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1268
            /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1269
             * allocation failed ...
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1270
             * ... fall through to trigger the error
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1271
             */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1272
        }
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1273
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1274
%}.
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1275
    index0 := index := digitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1276
    [(index > 0) and:[(digitByteArray at:index) == 0]] whileTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1277
        index := index - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1278
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1279
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1280
    (index ~~ index0) ifTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1281
        digitByteArray := digitByteArray copyFrom:1 to:index
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1282
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1283
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1284
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1285
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1286
value:aSmallInteger
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1287
    "setup my contents to represent the same value as aSmallInteger.
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
  1288
     This method will fail, if the argument is not a smallInteger.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1289
     This should only be used internally, 
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1290
     since it will create an unnormalized LargeInt (by purpose) if asked for."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1291
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1292
    |absValue 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1293
     b1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1294
     b2 "{ Class: SmallInteger }"
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1295
     b3 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1296
     b4 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1297
     b5 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1298
     b6 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1299
     b7 "{ Class: SmallInteger }"|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1300
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1301
    "
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1302
     could have simply created a 4-byte largeinteger and normalize it. 
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1303
     The code below does the normalize right away, avoiding the
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1304
     overhead of producing any intermediate byte-arrays (and the scanning)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1305
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1306
    (aSmallInteger == 0) ifTrue: [
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1307
        digitByteArray := ByteArray with:0.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1308
        sign := 0.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1309
        ^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1310
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1311
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1312
    (aSmallInteger < 0) ifTrue: [
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1313
        sign := -1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1314
        absValue := aSmallInteger negated
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1315
    ] ifFalse: [
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1316
        sign := 1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1317
        absValue := aSmallInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1318
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1319
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1320
    b1 := absValue bitAnd:16rFF.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1321
    absValue := absValue bitShift:-8.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1322
    absValue == 0 ifTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1323
        digitByteArray := ByteArray with:b1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1324
    ] ifFalse:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1325
        b2 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1326
        absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1327
        absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1328
            digitByteArray := ByteArray with:b1 with:b2
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1329
        ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1330
            b3 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1331
            absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1332
            absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1333
                digitByteArray := ByteArray with:b1 with:b2 with:b3
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1334
            ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1335
                b4 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1336
                absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1337
                absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1338
                    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1339
                ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1340
                    b5 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1341
                    absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1342
                    absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1343
                        digitByteArray := ByteArray new:5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1344
                        digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1345
                        digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1346
                        digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1347
                        digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1348
                        digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1349
                    ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1350
                        b6 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1351
                        absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1352
                        absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1353
                            digitByteArray := ByteArray new:6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1354
                            digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1355
                            digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1356
                            digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1357
                            digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1358
                            digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1359
                            digitByteArray at:6 put:b6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1360
                        ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1361
                            b7 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1362
                            absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1363
                            absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1364
                                digitByteArray := ByteArray new:7.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1365
                                digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1366
                                digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1367
                                digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1368
                                digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1369
                                digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1370
                                digitByteArray at:6 put:b6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1371
                                digitByteArray at:7 put:b7.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1372
                            ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1373
                                digitByteArray := ByteArray new:8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1374
                                digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1375
                                digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1376
                                digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1377
                                digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1378
                                digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1379
                                digitByteArray at:6 put:b6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1380
                                digitByteArray at:7 put:b7.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1381
                                digitByteArray at:8 put:absValue.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1382
                            ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1383
                        ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1384
                    ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1385
                ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1386
            ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1387
        ]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1388
    ]
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  1389
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1390
    "Modified: / 26.5.1999 / 22:18:14 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1391
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1392
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1393
!LargeInteger methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1394
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1395
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1396
    "return true, if the argument, aNumber is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1397
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1398
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1399
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1400
    (aNumber class == self class) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1401
	^ self retry:#< coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1402
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1403
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1404
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1405
    (sign > 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1406
	"I am positive"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1407
	(otherSign > 0) ifTrue:[^ self absLess:aNumber].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1408
	^ false "aNumber is <= 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1409
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1410
    (sign == 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1411
	(otherSign > 0) ifTrue:[^ true].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1412
	^ false
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1413
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1414
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1415
    (otherSign > 0) ifTrue:[^ true].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1416
    (otherSign == 0) ifTrue:[^ true].
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1417
    ^ (aNumber absLess:self)
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1418
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1419
    "Modified: / 14.1.1998 / 12:51:42 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1420
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1421
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1422
= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1423
    "return true, if the argument, aNumber has the same value as
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1424
     the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1425
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1426
    "/ speed up compare to 0
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1427
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1428
    (aNumber == 0 and:[sign == 0]) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1429
	^ true
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1430
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1431
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1432
    (aNumber class == self class) ifFalse:[
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1433
	"/
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1434
	"/ here, we depend on the fact, that largeinteger
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1435
	"/ results are always converted to smallInts, if possible.
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1436
	"/ therefore, a largeInt in the smallInt range is not allowed (possible)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1437
	"/
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1438
	aNumber class == SmallInteger ifTrue:[^ false ].
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1439
	aNumber respondsToArithmetic ifFalse:[ ^ false ].
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1440
	^ self retry:#= coercing:aNumber
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1441
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1442
    (aNumber sign == sign) ifFalse:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1443
    ^ self absEq:aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1444
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1445
    "Modified: / 13.2.1998 / 11:43:15 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1446
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1447
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1448
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1449
    "return true, if the argument, aNumber is less than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1450
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1451
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1452
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1453
    (aNumber class == self class) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1454
	^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1455
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1456
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1457
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1458
    (sign > 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1459
	"I am positive"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1460
	(otherSign > 0) ifTrue:[^ aNumber absLess:self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1461
	^ true "aNumber is <= 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1462
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1463
    (sign == 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1464
	"I am zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1465
	(otherSign > 0) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1466
	^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1467
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1468
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1469
    (otherSign > 0) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1470
    (otherSign == 0) ifTrue:[^ false].
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1471
    ^ (self absLess:aNumber)  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1472
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1473
    "Modified: / 14.1.1998 / 12:56:56 / cg"
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1474
!
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1475
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1476
hash
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1477
    "return an integer useful for hashing on large numbers"
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1478
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1479
    ^ (self bitAnd:16r3FFFFFFF)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1480
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1481
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1482
!LargeInteger methodsFor:'double dispatching'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1483
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1484
differenceFromInteger:anInteger
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1485
    "sent, when anInteger does not know how to subtract the receiver.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1486
     Return the result of 'anInteger - self'. The argument must be a SmallInteger."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1487
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1488
    anInteger > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1489
	sign > 0 ifTrue:[
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1490
	    ^ self absFastMinus:anInteger sign:-1
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1491
	].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1492
	^ self absFastPlus:anInteger sign:1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1493
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1494
    anInteger == 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1495
	^ self negated
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1496
    ].
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1497
    sign > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1498
	^ self absFastPlus:anInteger negated sign:-1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1499
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1500
    ^ self absFastMinus:anInteger sign:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1501
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1502
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1503
     12345678901234567890          
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1504
     -12345678901234567890         
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1505
     12345678901234567890 differenceFromInteger:0       
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1506
     12345678901234567890 differenceFromInteger:1       
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1507
     12345678901234567890 differenceFromInteger:-1      
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1508
     -12345678901234567890 differenceFromInteger:1   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1509
     -12345678901234567890 differenceFromInteger:-1   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1510
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1511
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1512
    "Modified: 20.10.1996 / 18:41:54 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1513
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1514
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1515
productFromInteger:anInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1516
    "sent, when anInteger does not know how to multiply the receiver.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1517
     Return the product of the receiver and the argument, aSmallInteger"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1518
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1519
    |num result 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1520
     resultDigitByteArray
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1521
     val     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1522
     len     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1523
     carry   "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  1524
     prod    "{ Class: SmallInteger }" 
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1525
     ok lResult|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1526
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1527
    "multiplying by a small integer is done here"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1528
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1529
    "trivial cases"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1530
    anInteger == 0 ifTrue:[^ 0].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1531
    anInteger == 1 ifTrue:[^ self].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1532
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1533
    num := anInteger abs.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1534
    (num > 16r3FFFFF) ifTrue:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1535
        "if num is too big (so that multiplying by a byte could create a Large)"
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1536
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1537
        ^ anInteger retry:#* coercing:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1538
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1539
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1540
    len := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1541
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1542
    val := num.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1543
    val <= 16rFF ifTrue:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1544
        lResult := len + 1.
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1545
    ] ifFalse:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1546
        val <= 16rFFFF ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1547
            lResult := len + 2
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1548
        ] ifFalse:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1549
            val <= 16rFFFFFF ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1550
                lResult := len + 4.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1551
            ] ifFalse:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1552
                lResult := len + 6.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1553
            ]
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1554
        ]
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1555
    ].
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  1556
    resultDigitByteArray := ByteArray uninitializedNew:lResult.
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2855
diff changeset
  1557
    result := self class basicNew setDigits:resultDigitByteArray.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1558
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1559
    anInteger < 0 ifTrue:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1560
        sign > 0 ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1561
            result sign:-1
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1562
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1563
    ] ifFalse:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1564
        sign < 0 ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1565
            result sign:sign
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1566
        ]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1567
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1568
85
claus
parents: 77
diff changeset
  1569
    ok := false.
claus
parents: 77
diff changeset
  1570
%{
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1571
    OBJ __digitByteArray = __INST(digitByteArray);
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1572
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1573
    if (__isSmallInteger(len)
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1574
     && __isByteArray(__digitByteArray)
85
claus
parents: 77
diff changeset
  1575
     && __isByteArray(resultDigitByteArray)) {
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1576
        INT _l = __intVal(len);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1577
        INT _v = __intVal(val);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1578
        unsigned INT _carry = 0;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1579
        unsigned INT _prod;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1580
        unsigned char *digitP = __ByteArrayInstPtr(__digitByteArray)->ba_element;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1581
        unsigned char *resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1582
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1583
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1584
         * skipping zeros does not help much (a few percent) on
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1585
         * a P5 or other CPUS with a fast multiplier. 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1586
         * It may make more of a difference on CPUs with slower 0-multiply.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1587
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1588
        while ((_l >= sizeof(INT)) && (((unsigned INT *)digitP)[0] == 0)) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1589
             ((unsigned long *)resultP)[0] = 0;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1590
            digitP += sizeof(INT);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1591
            resultP += sizeof(INT);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1592
            _l -= sizeof(INT);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1593
        }
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1594
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1595
#if defined(i386) || defined(alpha) /* XXX actually: LSB_FIRST */
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1596
# if defined (__GNUC__) && defined(i386)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1597
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1598
         * can do it long-word-wise;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1599
         * 32*32 -> 64 multiplication
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1600
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1601
        while (_l > 3) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1602
            unsigned __pHi, __pLow;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1603
	    unsigned __digit;
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1604
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1605
            /* 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1606
             * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1607
             * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1608
             */
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1609
	    __digit = ((unsigned long *)digitP)[0];
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1610
            asm ("mull %3               \n
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1611
                  addl %4,%%eax         \n
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1612
                  adcl $0,%%edx"    
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1613
                    : "=a"  (__pLow),
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1614
                      "=d"  (__pHi)
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1615
                    : "0"   (__digit),
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1616
                      "1"   ((unsigned long)(_v)),
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1617
                      "rm"  ((unsigned long)(_carry)) );
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1618
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1619
            ((unsigned long *)resultP)[0] = __pLow;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1620
            _carry = __pHi;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1621
            digitP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1622
            resultP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1623
            _l -= 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1624
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1625
# else /* not GNU-i386 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1626
#  if defined (WIN32) && defined(i386)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1627
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1628
         * can do it long-word-wise;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1629
         * 32*32 -> 64 multiplication
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1630
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1631
        while (_l > 3) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1632
            unsigned __pLow;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1633
            unsigned digit; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1634
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1635
            /* 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1636
             * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1637
             * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1638
             */
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1639
/*
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1640
            digit = ((unsigned long *)digitP)[0]; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1641
            edx::eax = (digit * _v);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1642
            edx::eax += _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1643
            ((unsigned long *)resultP)[0] = eax; -- pLow
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1644
            _carry = edx; -- pHigh
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1645
            digitP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1646
            resultP += 4;
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1647
*/
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1648
            digit = ((unsigned long *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1649
            asm {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1650
                mov   eax, digit
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1651
                mov   edx, _v
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1652
                mul   edx
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1653
                add   eax, _carry
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1654
                adc   edx, 0 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1655
                mov   __pLow, eax
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1656
                mov   _carry, edx
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1657
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1658
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1659
            ((unsigned long *)resultP)[0] = __pLow; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1660
            digitP += 4; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1661
            resultP += 4; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1662
            _l -= 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1663
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1664
#  else /* not WIN32-i386 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1665
#   if defined(INT64)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1666
        if (_v <= 0xFFFFFFFFL) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1667
            /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1668
             * have a 64bit int type ... good
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1669
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1670
            UINT64 _prod64;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1671
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1672
            /* have 64bit ints; can do it int-wise
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1673
             *
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1674
             * max: 0xFFFFFFFF * 0xFFFFFFFF -> 0xFFFFFFFE.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1675
             * + maxCarry (0xFFFFFFFF)  -> 0xFFFFFFFF.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1676
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1677
            while (_l > 3) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1678
                unsigned __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1679
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1680
                __t = ((unsigned *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1681
                digitP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1682
                _prod64 = (INT64)_v;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1683
                _prod64 *= __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1684
                _prod64 += _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1685
                ((unsigned *)resultP)[0] = _prod64 /* & 0xFFFFFFFFL */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1686
                _carry = _prod64 >> 32;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1687
                resultP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1688
                _l -= 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1689
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1690
            if (_l > 1) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1691
                unsigned short __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1692
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1693
                __t = ((unsigned short *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1694
                digitP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1695
                _prod64 = (INT64)_v;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1696
                _prod64 *= __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1697
                _prod64 += _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1698
                ((unsigned short *)resultP)[0] = _prod64 /* & 0xFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1699
                _carry = _prod64 >> 16;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1700
                resultP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1701
                _l -= 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1702
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1703
            if (_l > 0) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1704
                _prod64 = *digitP++ * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1705
                *resultP++ = _prod64 /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1706
                _carry = _prod64 >> 8;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1707
                _l--;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1708
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1709
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1710
#   else /* no INT64 type */
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1711
        if (_v <= 0xFFFF) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1712
            /* can do it short-wise 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1713
             * 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1714
             * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1715
             * + maxCarry (0xFFFF)  -> 0xFFFF.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1716
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1717
            while (_l > 1) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1718
                _prod = ((unsigned short *)digitP)[0] * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1719
                ((unsigned short *)resultP)[0] = _prod /* & 0xFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1720
                _carry = _prod >> 16;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1721
                digitP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1722
                resultP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1723
                _l -= 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1724
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1725
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1726
#   endif /* no INT64 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1727
#  endif /* not WIN32-i386 */
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  1728
# endif /* not GNU-i386 */
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  1729
#else /* not LSB_FIRST */
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1730
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1731
# ifdef mips
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1732
#  define LOAD_WORD_WISE
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1733
   /* no, STORE_WORD_WISE makes it slower */
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1734
# endif
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1735
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1736
        if (_v <= 0xFFFF) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1737
            /* can do it short-wise 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1738
             * 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1739
             * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1740
             * + maxCarry (0xFFFF)  -> 0xFFFF.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1741
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1742
            while (_l > 1) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1743
                unsigned int t;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1744
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1745
#if defined(LOAD_WORD_WISE)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1746
                /* better fetch short-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1747
                t = ((unsigned short *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1748
                digitP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1749
                t = ((t >> 8) | (t << 8)) & 0xFFFF;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1750
#else
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1751
                t = (digitP[1]<<8) + digitP[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1752
                digitP += 2;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1753
#endif
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1754
                _prod = t * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1755
                _carry = _prod >> 16;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1756
#if defined(STORE_WORD_WISE)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1757
                /* better store short-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1758
                _prod = ((_prod >> 8) | (_prod << 8)) & 0xFFFF;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1759
                ((unsigned short *)resultP)[0] = _prod;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1760
#else
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1761
                resultP[0] = _prod /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1762
                resultP[1] = (_prod>>8) /* & 0xFF */;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1763
#endif
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1764
                resultP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1765
                _l -= 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1766
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1767
        }
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  1768
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  1769
#endif /* LSB_FIRST */
1797
8dafe47b33fd faster multiplication by an integer.
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
  1770
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1771
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1772
         * rest is done byte-wise
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1773
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1774
        while (_l > 0) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1775
            _prod = *digitP++ * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1776
            *resultP++ = _prod /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1777
            _carry = _prod >> 8;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1778
            _l--;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1779
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1780
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1781
        _l = __intVal(lResult) - __intVal(len);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1782
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1783
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1784
         * remaining carry
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1785
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1786
        while (_carry) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1787
            *resultP++ = _carry /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1788
            _carry >>= 8;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1789
            _l--;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1790
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1791
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1792
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1793
         * remaining zeros
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1794
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1795
        while (_l--) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1796
            *resultP++ = 0;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1797
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1798
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1799
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1800
         * need compress ?
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1801
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1802
        if (resultP[-1]) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1803
            /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1804
             * no
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1805
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1806
            RETURN(result);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1807
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1808
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1809
        ok = true;
85
claus
parents: 77
diff changeset
  1810
    }
claus
parents: 77
diff changeset
  1811
%}.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1812
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1813
     fall back - normally not reached
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1814
     (could make it a primitive-failure as well)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1815
    "
85
claus
parents: 77
diff changeset
  1816
    ok ifFalse:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1817
        carry := 0.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1818
        1 to:len do:[:i |
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1819
            prod := (digitByteArray basicAt:i) * val + carry.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1820
            resultDigitByteArray basicAt:i put:(prod bitAnd:16rFF).
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1821
            carry := prod bitShift:-8.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1822
        ].
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1823
        [carry ~~ 0] whileTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1824
            len := len + 1.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1825
            resultDigitByteArray basicAt:len put:(carry bitAnd:16rFF).
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1826
            carry := carry bitShift:-8
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1827
        ].
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1828
        [len < lResult] whileTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1829
            len := len + 1.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1830
            resultDigitByteArray basicAt:len put:0
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1831
        ]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1832
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1833
    ^ result compressed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1834
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1835
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1836
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1837
    "sent, when anInteger does not know how to add the receiver.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1838
     Return the sum of the receiver and the argument, (which must be a SmallInteger)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1839
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1840
    anInteger > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1841
	sign > 0 ifTrue:[
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1842
	    ^ self absFastPlus:anInteger sign:1
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1843
	].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1844
	^ self absFastMinus:anInteger sign:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1845
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1846
    anInteger == 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1847
	^ self
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1848
    ].
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1849
    sign > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1850
	^ self absFastMinus:anInteger sign:1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1851
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1852
    ^ self absFastPlus:anInteger sign:-1
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1853
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1854
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1855
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1856
     12345678901234567890          
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1857
     -12345678901234567890         
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1858
     12345678901234567890 sumFromInteger:0       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1859
     -12345678901234567890 sumFromInteger:0       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1860
     12345678901234567890 sumFromInteger:1       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1861
     12345678901234567890 sumFromInteger:-1      
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1862
     -12345678901234567890 sumFromInteger:1     
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1863
     -12345678901234567890 sumFromInteger:-1   
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1864
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1865
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1866
    "Modified: / 9.1.1998 / 13:27:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1867
! !
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1868
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1869
!LargeInteger methodsFor:'printing & storing'!
345
claus
parents: 250
diff changeset
  1870
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1871
storeOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1872
    "append a representation of the receiver to aStream, which can
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1873
     be used to reconstruct the receiver."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1874
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1875
    self printOn:aStream.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1876
    aStream nextPutAll:' asLargeInteger'
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1877
! !
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1878
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1879
!LargeInteger methodsFor:'private'!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1880
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1881
absDivMod:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1882
    "return an array with two LargeIntegers representing
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1883
     abs(self) // abs(theArgument) and abs(self) \\ abs(theArgument).
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1884
     Used as a helper for \\, //, rem: and quo:.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1885
     This method needs a rewrite."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1886
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1887
    |dividend divisor 
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1888
     quo digits
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1889
     shift "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1890
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1891
    anInteger == 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1892
        ^ DivisionByZeroSignal raiseRequest
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1893
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1894
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1895
    self = anInteger ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1896
        ^ Array with:1 with:0
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1897
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1898
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1899
    shift := self highBit - anInteger highBit.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1900
    dividend := self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1901
    shift < 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1902
        ^ Array with:0 with:dividend.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1903
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  1904
    shift == 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1905
        divisor := anInteger simpleDeepCopy.
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  1906
    ] ifFalse:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1907
        divisor := anInteger bitShift:shift.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1908
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1909
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1910
    quo := self class basicNew numberOfDigits:((shift // 8) + 1). 
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1911
    digits := quo digitBytes.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1912
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1913
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1914
    [shift > 0] whileTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1915
        (dividend absLess:divisor) ifFalse:[
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1916
            digits bitSetAt:shift.
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1917
            (dividend absSubtract: divisor) ifFalse:[ "result == 0"
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1918
                ^ Array with:quo compressed with:dividend compressed            
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1919
            ].
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1920
        ].
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1921
        shift := shift - 1.
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1922
        divisor div2.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1923
    ].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1924
    ^ Array with:quo compressed with:dividend compressed
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1925
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1926
    "
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1927
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:4000000000] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1928
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:3000000000] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1929
     16000000000 absDivMod:4000000000 
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1930
     16000000000 absDivMod:3000000000
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1931
    "
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1932
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1933
    "Modified: / 5.11.1996 / 18:40:24 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1934
    "Created: / 27.4.1999 / 19:45:44 / stefan"
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1935
    "Modified: / 26.7.1999 / 10:46:36 / stefan"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1936
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1937
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1938
absEq:aLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1939
    "return true, if abs(self) = abs(theArgument)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1940
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1941
    |len1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1942
     len2 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1943
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1944
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1945
     otherDigitByteArray |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1946
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1947
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1948
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1949
    len2 := otherDigitByteArray size.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1950
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1951
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1952
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1953
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1954
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1955
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1956
    [(digitByteArray basicAt:len1) == 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1957
        len1 := len1 - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1958
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1959
    [(otherDigitByteArray basicAt:len2) == 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1960
        len2 := len2 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1961
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1962
    (len1 ~~ len2) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1963
    [len1 > 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1964
        d1 := digitByteArray basicAt:len1.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1965
        d2 := otherDigitByteArray basicAt:len1.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1966
        (d1 ~~ d2) ifTrue:[^ false].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1967
        len1 := len1 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1968
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1969
    ^ true
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1970
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1971
    "Modified: / 8.5.1999 / 18:37:02 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1972
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1973
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1974
absFastDivMod:aPositiveSmallInteger
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1975
    "return an array with two LargeIntegers representing
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1976
     abs(self) // aPositiveSmallInteger and 
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1977
     abs(self) \\ aPositiveSmallInteger."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1978
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1979
    |tmp1     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1980
     prevRest "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1981
     count    "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  1982
     newDigitByteArray result
claus
parents: 77
diff changeset
  1983
     ok|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1984
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  1985
    aPositiveSmallInteger == 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1986
        ^ DivisionByZeroSignal raiseRequest
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1987
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1988
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1989
"This cannot happen (if always normalized)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  1990
    self < aPositiveSmallInteger ifTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1991
        ^ Array with:0 with:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1992
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1993
"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1994
    count := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1995
    result := self class basicNew numberOfDigits:count.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1996
    newDigitByteArray := result digitBytes.
85
claus
parents: 77
diff changeset
  1997
    ok := false.
claus
parents: 77
diff changeset
  1998
%{
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  1999
    OBJ __digits;
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2000
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2001
    __digits = __INST(digitByteArray);
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2002
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2003
    if (__isByteArray(__digits)
85
claus
parents: 77
diff changeset
  2004
     && __isByteArray(newDigitByteArray)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2005
     && __bothSmallInteger(count, aPositiveSmallInteger)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2006
        unsigned INT rest = 0;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2007
        int index = __intVal(count);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2008
        int index0;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2009
        unsigned INT divisor = __intVal(aPositiveSmallInteger);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2010
        unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2011
        unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2012
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2013
        index0 = index - 1;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2014
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2015
        /* 
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2016
         * divide short-wise 
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2017
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2018
        if (divisor <= 0xFFFF) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2019
            if ((index & 1) == 0) { /* even number of bytes */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2020
                while (index > 1) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2021
                    unsigned INT t;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2022
                    unsigned INT div;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2023
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2024
#if defined(__LSBFIRST) || defined(i386)
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2025
                    index -= 2;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2026
                    t = *((unsigned short *)(&digitBytes[index]));
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2027
# else
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2028
                    index--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2029
                    t = digitBytes[index];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2030
                    index--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2031
                    t = (t << 8) | digitBytes[index];
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2032
# endif
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2033
                    t = t | (rest << 16);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2034
                    div = t / divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2035
                    rest = t % divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2036
#if defined(__LSBFIRST) || defined(i386)
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2037
                    *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2038
# else
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2039
                    resultBytes[index+1] = div >> 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2040
                    resultBytes[index] = div /* & 0xFF */;
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2041
# endif
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2042
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2043
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2044
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2045
        while (index > 0) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2046
            unsigned INT t;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2047
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2048
            index--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2049
            t = digitBytes[index];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2050
            t = t | (rest << 8);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2051
            resultBytes[index] = t / divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2052
            rest = t % divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2053
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2054
        prevRest = __MKSMALLINT(rest);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2055
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2056
        /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2057
         * no need to normalize ?
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2058
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2059
        while ((index0 >= sizeof(INT)) && (resultBytes[index0]==0)) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2060
            index0--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2061
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2062
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2063
        if (index0 > sizeof(INT)) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2064
            RETURN ( __ARRAY_WITH2(result, prevRest));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2065
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2066
        if ((index0 == sizeof(INT))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2067
         && resultBytes[index0] >= 0x40) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2068
            RETURN ( __ARRAY_WITH2(result, prevRest));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2069
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2070
        /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2071
         * must compress
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2072
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2073
        ok = true;
85
claus
parents: 77
diff changeset
  2074
    }
claus
parents: 77
diff changeset
  2075
%}.
claus
parents: 77
diff changeset
  2076
    "
claus
parents: 77
diff changeset
  2077
     slow code - not normally reached
claus
parents: 77
diff changeset
  2078
     (could also do a primitiveFailure here)
claus
parents: 77
diff changeset
  2079
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2080
    ok ifFalse:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2081
        self primitiveFailed
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2082
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2083
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  2084
    ^ Array with:(result compressed) with:prevRest
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2085
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2086
    "
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2087
     ((16r1234 asLargeInteger absFastDiv:16rffff) at:2) printStringRadix:16
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2088
     ((16r00123456 asLargeInteger absFastDiv:16rffffff) at:2) printStringRadix:16
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2089
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2090
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2091
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2092
absFastMinus:aSmallInteger sign:newSign
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2093
    "return a LargeInteger representing abs(self) - abs(theArgument)
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2094
     with sign: newSign.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2095
     The result is normalized.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2096
     This is a helper for addition and subtraction - not for public use."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2097
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2098
    |result resultDigitByteArray lastDigit ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2099
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2100
     rsltLen "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2101
     index   "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2102
     borrow  "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2103
     diff    "{ Class: SmallInteger }" |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2104
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2105
    "/ the following code only works with
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2106
    "/ smallIntegers in the range _MIN_INT+255 .. _MAX_INT-255
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2107
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2108
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2109
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2110
        ^ self absMinus:(LargeInteger value:aSmallInteger) sign:newSign.
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2111
    ]. 
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2112
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2113
    len := digitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2114
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2115
    rsltLen := len "+ 1".
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2116
    result := self class basicNew numberOfDigits:rsltLen.
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2117
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2118
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2119
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2120
    borrow := aSmallInteger abs.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2121
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2122
%{
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2123
    if (__isByteArray(__INST(digitByteArray))
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2124
     && __isByteArray(resultDigitByteArray)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2125
        unsigned INT __borrow = __intVal(borrow);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2126
        INT __diff;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2127
        int __index = 1;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2128
        int __len = __intVal(len);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2129
        unsigned char *__digitP = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2130
        unsigned char *__resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2131
        int __len3;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2132
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2133
#if defined(alpha64)
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2134
        /* 
4948
adfadf9b2c75 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4947
diff changeset
  2135
         * subtract int-wise 
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2136
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2137
        __len3 = __len - 3;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2138
        while (__index < __len3) {
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2139
            /* do not make this into one expression - ask cg why */
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2140
            __diff = ((unsigned int *)(__digitP + __index-1))[0];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2141
            __diff -= (__borrow & 0xFFFFFFFFL);
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2142
            __borrow >>= 32;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2143
            if (__diff < 0) {
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2144
                /* __diff += 0x100000000; */
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2145
                __borrow++;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2146
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2147
            ((unsigned int *)(__resultP+__index-1))[0] = __diff;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2148
            __index += 4;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2149
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2150
#endif
4182
a867ecbf5e56 tuned abdFastMinus:
Claus Gittinger <cg@exept.de>
parents: 4181
diff changeset
  2151
#if defined(__LSBFIRST) || defined(i386)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2152
        /* 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2153
         * subtract short-wise 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2154
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2155
        while (__index < __len) {
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2156
            /* do not make this into one expression - ask cg why */
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2157
            __diff = ((unsigned short *)(__digitP+__index-1))[0];
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2158
            __diff -= (__borrow & 0xFFFF);
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2159
            __borrow >>= 16;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2160
            if (__diff < 0) {
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2161
                /* __diff += 0x10000; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2162
                __borrow++;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2163
            } else {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2164
                if (__borrow == 0) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2165
                    ((unsigned short *)(__resultP+__index-1))[0] = __diff;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2166
                    __index += 2;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2167
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2168
                    /* nothing more to subtract .. */
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2169
                    while (__index < __len) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2170
                        ((unsigned short *)(__resultP+__index-1))[0] = ((unsigned short *)(__digitP+__index-1))[0];
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2171
                        __index += 2;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2172
                    }
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2173
                    if (__index <= __len) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2174
                        __resultP[__index-1] = __digitP[__index-1];
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2175
                    }
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2176
                    break;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2177
                }
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2178
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2179
            ((unsigned short *)(__resultP+__index-1))[0] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2180
            __index += 2;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2181
        }
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2182
#endif
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2183
        /* 
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2184
         * subtract byte-wise 
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2185
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2186
        while (__index <= __len) {
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2187
            __diff = __digitP[__index-1];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2188
            __diff -= (__borrow & 0xFF);
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2189
            __borrow >>= 8;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2190
            if (__diff < 0) {
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2191
                /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2192
                __borrow++;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2193
            } else {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2194
                if (__borrow == 0) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2195
                    __resultP[__index-1] = __diff;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2196
                    __index++;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2197
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2198
                    /* nothing more to subtract .. */
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2199
                    while (__index <= __len) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2200
                        __resultP[__index-1] = __digitP[__index-1];
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2201
                        __index++;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2202
                    }
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2203
                    break;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2204
                }
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2205
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2206
            __resultP[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2207
            __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2208
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2209
        lastDigit = __MKSMALLINT( __resultP[__index-1-1] );
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2210
        ok = true;
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2211
    }
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2212
%}.
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2213
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2214
    ok == true ifFalse:[        "/ cannot happen
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2215
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2216
        [borrow ~~ 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2217
            (index <= len) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2218
                diff := (digitByteArray basicAt:index) - (borrow bitAnd:16rFF).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2219
                borrow := borrow bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2220
                diff < 0 ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2221
                    diff := diff + 256.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2222
                    borrow := borrow + 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2223
                ]
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2224
            ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2225
                diff := borrow bitAnd:255.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2226
                borrow := borrow bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2227
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2228
            resultDigitByteArray basicAt:index put:(lastDigit := diff).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2229
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2230
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2231
        [index <= len] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2232
            resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2233
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2234
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2235
        (index <= rsltLen) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2236
            lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2237
        ]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2238
    ].
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2239
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2240
    (lastDigit == 0 or:[rsltLen <= SmallInteger maxBytes]) ifTrue:[ 
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2241
        ^ result compressed.
4182
a867ecbf5e56 tuned abdFastMinus:
Claus Gittinger <cg@exept.de>
parents: 4181
diff changeset
  2242
    ]. 
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2243
    ^ result
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2244
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2245
    "                                                          
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2246
     12345678900000000000 absFastMinus:1 sign:1       
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2247
     12345678900000000000 absFastMinus:1 sign:-1      
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2248
     12345678900000000000 absFastMinus:1000000 sign:1 
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2249
     12345678900000000000 absFastMinus:255 sign:1     
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2250
     (SmallInteger maxVal + 1) absFastMinus:1 sign:1
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2251
     (SmallInteger minVal - 1) absFastMinus:1 sign:1  
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2252
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2253
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2254
    "Modified: 24.3.1997 / 21:33:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2255
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2256
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2257
absFastPlus:aSmallInteger sign:newSign
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2258
    "return a LargeInteger representing abs(self) + abs(theArgument).
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2259
     with sign: newSign.
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2260
     The result is normalized. The argument must be a smallInteger
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2261
     with byteSize one less than the integer byteSize.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2262
     This is a helper for addition and subtraction - not for public use."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2263
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2264
    |result resultDigitByteArray lastDigit
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2265
     ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2266
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2267
     rsltLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2268
     index "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2269
     carry "{ Class: SmallInteger }" |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2270
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2271
    "/ the following code only works with
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2272
    "/ smallIntegers in the range _MIN_INT+255 .. _MAX_INT-255
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2273
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2274
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2275
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2276
        ^ self absPlus:(LargeInteger value:aSmallInteger) sign:newSign.
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2277
    ]. 
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2278
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2279
    len := rsltLen := digitByteArray size.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2280
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2281
    "/ there can only be an overflow from the high byte,
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2282
    "/ if it is 255 (since the other number is definitely smaller)
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2283
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2284
    (digitByteArray at:len) == 16rFF ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2285
        rsltLen := len + 1.
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2286
    ] ifFalse:[
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2287
        "/ or the argument has something in the high byte ..
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2288
%{
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2289
#ifdef alpha64
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2290
        if (__intVal(aSmallInteger) & 0xFF00000000000000L) {
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2291
            rsltLen = __MKSMALLINT(__intVal(len) + 1);
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2292
        }
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2293
#else
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2294
        if (__intVal(aSmallInteger) & 0xFF000000) {
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2295
            rsltLen = __MKSMALLINT(__intVal(len) + 1);
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2296
        }
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2297
#endif
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2298
%}
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2299
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2300
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2301
    result := self class basicNew numberOfDigits:rsltLen.
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2302
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2303
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2304
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2305
%{
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2306
    if (__isByteArray(__INST(digitByteArray))
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2307
     && __isByteArray(resultDigitByteArray)
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2308
     && __isSmallInteger(aSmallInteger)) {
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2309
        /* carry is NOT unsigned (see negation below) */
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2310
        INT __carry = __intVal(aSmallInteger);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2311
        int __index = 1;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2312
        int __len = __intVal(len);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2313
        unsigned char *__src = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2314
        unsigned char *__dst = (unsigned char *)(__ByteArrayInstPtr(resultDigitByteArray)->ba_element);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2315
        INT __ptrDelta = __dst - __src;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2316
        unsigned char *__srcLast = __src + __len - 1;
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2317
        int __rsltLen = __intVal(rsltLen);
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2318
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2319
        if (__carry < 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2320
            __carry = -__carry;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2321
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2322
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2323
#if defined(__LSBFIRST) || defined(i386) || defined(alpha)
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2324
# if defined(i386) && defined(__GNUC__)
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2325
#  if 0 /* NOTICE - the code below is 20% slower ... - why */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2326
        /*
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2327
         * add long-wise
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2328
         */
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2329
        asm("  jecxz nothingToDo     
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2330
               movl  %%eax, %%esi      /* __src input */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2331
               movl  %%ebx, %%edi      /* __dst input */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2332
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2333
               /* the first 4-byte int */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2334
               lodsl                   /* fetch */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2335
               addl  %%edx, %%eax      /* add */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2336
               stosl                   /* store */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2337
               leal  -1(%%ecx),%%ecx   /* do not clobber carry */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2338
               jecxz doneLoop          /* any more ? */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2339
               /* remaining 4-byte ints */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2340
               jmp   addLoop
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2341
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2342
               .align 8
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2343
             addLoop:
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2344
               movl  0(%%esi), %%ebx   /* fetch  */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2345
               jnc   copyLoop2
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2346
               movl  $0, %%eax 
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2347
               leal  4(%%esi), %%esi   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2348
               adcl  %%ebx, %%eax      /* & add carry from prev int */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2349
               leal  8(%%edi), %%edi   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2350
               movl  %%eax, -8(%%edi)  /* store */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2351
               leal  -1(%%ecx),%%ecx   /* do not clobber carry */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2352
               jecxz doneLoop          /* any more ? */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2353
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2354
               movl  0(%%esi), %%ebx   /* fetch  */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2355
               movl  $0, %%eax 
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2356
               leal  4(%%esi), %%esi   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2357
               adcl  %%ebx, %%eax      /* & add carry from prev int */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2358
               movl  %%eax, -4(%%edi)  /* store */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2359
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2360
               loop  addLoop
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2361
               jmp   doneLoop
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2362
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2363
               .align 8
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2364
             copyLoop:
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2365
               movl  0(%%esi), %%ebx   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2366
             copyLoop2:
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2367
               add   $4, %%esi   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2368
               add   $4, %%edi   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2369
               movl  %%ebx, -4(%%edi)   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2370
               loop  copyLoop
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2371
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2372
             doneLoop:
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2373
               movl  $0, %%edx         /* do not clobber carry (xorl clears it) */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2374
               adcl  $0, %%edx
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2375
               movl  %%esi, %%eax      /* __src output */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2376
             nothingToDo:           
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2377
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2378
            " : "=d"  ((unsigned long)(__carry)),
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2379
                "=a"  (__src)
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2380
              : "1"   (__src),
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2381
                "b"   (__dst),
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2382
                "c"   (__len / 4),
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2383
                "0"   (__carry)
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2384
              : "esi", "edi");
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2385
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2386
#  else
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2387
        {
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2388
            unsigned char *__srcLastX;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2389
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2390
            __srcLastX = __srcLast - 3 - 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2391
            while (__src <= __srcLastX) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2392
                unsigned int __sum, __sum2;
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2393
                unsigned __digit1, __digit2;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2394
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2395
                __digit1 = ((unsigned *)__src)[0];
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2396
                __digit2 = ((unsigned *)__src)[1];
4286
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2397
                asm ("addl %%edx,%%ecx
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2398
                      adcl $0, %%eax
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2399
                      movl $0, %%edx
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2400
                      adcl $0, %%edx"    
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2401
                        : "=d"  ((unsigned long)(__carry)),
4286
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2402
                          "=c"  ((unsigned long)(__sum)),
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2403
                          "=a"  ((unsigned long)(__sum2))
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2404
                        : "0"   ((unsigned long)(__carry)),
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2405
                          "1"   (__digit1),
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2406
                          "2"   (__digit2));
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2407
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2408
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2409
                ((unsigned int *)(__src + __ptrDelta))[1] = __sum2;
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2410
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2411
                __src += 8;  
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2412
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2413
                if (__carry == 0) {
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2414
                    while (__src <= __srcLastX) {
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2415
                        /* copy over words */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2416
                        ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2417
                        ((unsigned int *)(__src + __ptrDelta))[1] = ((unsigned int *)__src)[1];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2418
                        __src += 8;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2419
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2420
                    while (__src <= __srcLast) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2421
                        /* copy over bytes */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2422
                        __src[__ptrDelta] = __src[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2423
                        __src ++;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2424
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2425
                    goto doneSource;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2426
                }
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2427
            }
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2428
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2429
            __srcLastX = __srcLastX + 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2430
            if (__src <= __srcLastX) {
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2431
                unsigned int __sum, __digit;
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2432
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2433
                __digit = ((unsigned *)__src)[0];
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2434
4286
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2435
                asm ("addl %%eax,%%edx
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2436
                      movl $0,%%eax
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2437
                      adcl $0,%%eax"    
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2438
                        : "=a"  ((unsigned long)(__carry)),
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2439
                          "=d"  ((unsigned long)(__sum))
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2440
                        : "0"   ((unsigned long)(__carry)),
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2441
                          "1"   (__digit) );
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2442
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2443
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2444
                __src += 4;  
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2445
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2446
                if (__carry == 0) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2447
                    while (__src <= __srcLast) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2448
                        /* copy over bytes */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2449
                        __src[__ptrDelta] = __src[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2450
                        __src ++;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2451
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2452
                    goto doneSource;
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2453
                }
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2454
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2455
        }
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2456
#  endif
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2457
# else 
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2458
#  if defined(i386) && defined(WIN32)
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2459
        {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2460
            unsigned char *__srcLast4;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2461
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2462
            /*
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2463
             * add long-wise
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2464
             */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2465
            __srcLast4 = __srcLast - 3;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2466
            while (__src <= __srcLast4) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2467
                unsigned int __sum;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2468
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2469
                __sum = ((unsigned int *)__src)[0];    
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2470
                asm {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2471
                      mov eax, __sum
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2472
                      add eax, __carry
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2473
                      mov edx, 0
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2474
                      adc edx, 0
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2475
                      mov __sum, eax
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2476
                      mov __carry, edx
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2477
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2478
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2479
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2480
                __src += 4;  
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2481
                if (__carry == 0) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2482
                    while (__src <= __srcLast4) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2483
                        /* copy over words */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2484
                        ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2485
                        __src += 4;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2486
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2487
                    while (__src <= __srcLast) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2488
                        /* copy over bytes */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2489
                        __src[__ptrDelta] = __src[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2490
                        __src ++;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2491
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2492
                    goto doneSource;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2493
                }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2494
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2495
        }
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2496
#  else 
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2497
#   ifdef alpha64
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2498
        {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2499
            unsigned char *__srcLast4;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2500
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2501
            /*
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2502
             * add long-wise
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2503
             */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2504
            __srcLast4 = __srcLast - 3;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2505
            while (__src <= __srcLast4) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2506
                unsigned INT __sum;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2507
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2508
                __sum = ((unsigned int *)__src)[0] + __carry;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2509
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum /* & 0xFFFF */;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2510
                __src += 4;  
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2511
                __carry = __sum >> 32;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2512
                if (__carry == 0) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2513
                    while (__src <= __srcLast4) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2514
                        /* copy over words */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2515
                        ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2516
                        __src += 4;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2517
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2518
                    while (__src <= __srcLast) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2519
                        /* copy over bytes */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2520
                        __src[__ptrDelta] = __src[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2521
                        __src ++;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2522
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2523
                    goto doneSource;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2524
                }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2525
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2526
        }
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2527
#   endif /* alpha64 */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2528
#  endif /* i386 & WIN32 */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2529
# endif /* i386 & GNUC */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2530
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2531
        /*
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2532
         * add short-wise
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2533
         */
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2534
        while (__src < __srcLast) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2535
            __carry += ((unsigned short *)__src)[0];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2536
            ((unsigned short *)(__src + __ptrDelta))[0] = __carry /* & 0xFFFF */;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2537
            __carry >>= 16;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2538
            __src += 2;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2539
        }
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2540
        /*
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2541
         * last (odd) byte
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2542
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2543
        if (__src <= __srcLast) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2544
            __carry += __src[0];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2545
            __src[__ptrDelta] = __carry /* & 0xFF */;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2546
            __carry >>= 8;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2547
            __src++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2548
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2549
#else /* not __LSBFIRST */
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2550
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2551
        /*
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2552
         * add byte-wise
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2553
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2554
        while (__src <= __srcLast) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2555
            __carry += __src[0];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2556
            __src[__ptrDelta] = __carry /* & 0xFF */;
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2557
            __src++;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2558
            __carry >>= 8;
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2559
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2560
            if (__carry == 0) {
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2561
                while (__src <= __srcLast) {
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2562
                    /* copy over rest */
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2563
                    __src[__ptrDelta] = __src[0];
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2564
                    __src++;
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2565
                }
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2566
                goto doneSource;
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2567
            }
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2568
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2569
#endif /* __LSBFIRST */
4185
375439993eb7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4182
diff changeset
  2570
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2571
    doneSource: ;
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2572
        /*
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2573
         * now, at most one other byte is to be stored ...
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2574
         */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2575
        if (__len < __rsltLen) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2576
            __src[__ptrDelta] = __carry /* & 0xFF */;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2577
            __src++;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2578
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2579
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2580
        if (__src[__ptrDelta-1]) {      /* lastDigit */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2581
            RETURN (result);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2582
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2583
        ok = true;
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2584
    }
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2585
%}.
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2586
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2587
    ok ~~ true ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2588
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2589
        carry := aSmallInteger abs.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2590
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2591
        [carry ~~ 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2592
            (index <= len) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2593
                carry := (digitByteArray basicAt:index) + carry.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2594
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2595
            resultDigitByteArray basicAt:index put:(lastDigit := carry bitAnd:16rFF).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2596
            carry := carry bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2597
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2598
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2599
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2600
        (index <= rsltLen) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2601
            [index <= len] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2602
                resultDigitByteArray basicAt:index put:(digitByteArray basicAt:index).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2603
                index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2604
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2605
            lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2606
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2607
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2608
        (lastDigit ~~ 0 and:[rsltLen > SmallInteger maxBytes]) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2609
            ^ result
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2610
        ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2611
    ].
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2612
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2613
    ^ result compressed
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2614
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2615
    "Modified: 24.3.1997 / 21:32:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2616
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2617
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2618
absLess:aLargeInteger
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2619
    "return true, if abs(self) < abs(theArgument).
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2620
     This handles unnormalized largeIntegers."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2621
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2622
    |myLen "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2623
     otherLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2624
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2625
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2626
     otherDigitByteArray |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2627
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2628
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2629
    otherDigitByteArray := aLargeInteger digitBytes.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2630
    otherLen := otherDigitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2631
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2632
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2633
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2634
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2635
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2636
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2637
    [myLen > 0 and:[(digitByteArray basicAt:myLen) == 0]] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2638
        myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2639
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2640
    [otherLen > 0 and:[(otherDigitByteArray basicAt:otherLen) == 0]] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2641
        otherLen := otherLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2642
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2643
    (myLen < otherLen) ifTrue:[^ true].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2644
    (myLen > otherLen) ifTrue:[^ false].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2645
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2646
    [myLen > 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2647
        d1 := digitByteArray basicAt:myLen.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2648
        d2 := otherDigitByteArray basicAt:myLen.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2649
        d1 == d2 ifFalse:[
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2650
            (d1 < d2) ifTrue:[^ true].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2651
            ^ false
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2652
        ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2653
        myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2654
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2655
    ^ false
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2656
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2657
    "Modified: / 3.5.1999 / 08:06:28 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2658
    "Modified: / 8.5.1999 / 18:37:11 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2659
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2660
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2661
absLessEq:aLargeInteger
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2662
    "return true, if abs(self) <= abs(theArgument).
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2663
     This handles unnormalized largeIntegers."
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2664
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2665
    |myLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2666
     otherLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2667
     d1   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2668
     d2   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2669
     otherDigitByteArray |
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2670
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2671
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2672
    otherDigitByteArray := aLargeInteger digitBytes.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2673
    otherLen := otherDigitByteArray size.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2674
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2675
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2676
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2677
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2678
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2679
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2680
    [(digitByteArray basicAt:myLen) == 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2681
        myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2682
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2683
    [(otherDigitByteArray basicAt:otherLen) == 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2684
        otherLen := otherLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2685
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2686
    (myLen < otherLen) ifTrue:[^ true].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2687
    (myLen > otherLen) ifTrue:[^ false].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2688
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2689
    [myLen > 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2690
        d1 := digitByteArray basicAt:myLen.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2691
        d2 := otherDigitByteArray basicAt:myLen.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2692
        d1 == d2 ifFalse:[
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2693
            (d1 < d2) ifTrue:[^ true].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2694
            ^ false.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2695
        ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2696
        myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2697
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2698
    ^ true
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2699
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2700
    "Created: / 13.2.1998 / 12:19:45 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2701
    "Modified: / 30.4.1999 / 12:46:31 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2702
    "Modified: / 8.5.1999 / 18:37:15 / cg"
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2703
!
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2704
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2705
absMinus:aLargeInteger sign:newSign
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2706
    "return a LargeInteger representing abs(self) - abs(theArgument)
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2707
     with sign: newSign.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2708
     The result is normalized. The argument must be a largeInteger
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2709
     with a byteSize smaller than the receivers byteSize.
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2710
     This is a helper for addition and subtraction - not for public use."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2711
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2712
    |result done
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2713
     otherDigitByteArray resultDigitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2714
     len1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2715
     len2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2716
     index  "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2717
     borrow "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2718
     diff   "{ Class: SmallInteger }"
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2719
     carry  "{ Class: SmallInteger }" 
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2720
     lastDigit   
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2721
     lResult ok|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2722
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2723
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2724
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2725
    len2 := otherDigitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2726
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2727
    len1 > len2 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2728
        lResult := len1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2729
    ] ifFalse:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2730
        lResult := (len1 max: len2) + 1.
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2731
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2732
    result := self class basicNew numberOfDigits:lResult.
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2733
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2734
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2735
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2736
    lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2737
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2738
%{
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2739
    OBJ _digitByteArray = __INST(digitByteArray);
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2740
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2741
    if (__isByteArray(_digitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2742
     && __isByteArray(otherDigitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2743
     && __isByteArray(resultDigitByteArray)) {
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2744
        int __len1 = __intVal(len1);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2745
        int __len2 = __intVal(len2);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2746
        int __minLen = __len1 < __len2 ? __len1 : __len2;
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2747
        int __index, __borrow = 0;
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2748
        INT __diff;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2749
        unsigned char *__myDigits, *__otherDigits, *__resultDigits;
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2750
        
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2751
        ok = true;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2752
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2753
        __resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2754
        __otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2755
        __myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2756
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2757
        __index = 1;
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2758
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2759
#if defined(alpha64)
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2760
        /*
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2761
         * subtract int-wise
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2762
         */
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2763
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2764
        while ((__index+3) <= __minLen) {
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2765
            /* do not make this into one expression - ask cg why */
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2766
            __diff = ((unsigned int *)(__myDigits+__index-1))[0]; 
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2767
            __diff -= ((unsigned int *)(__otherDigits+__index-1))[0];
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2768
            __diff -= __borrow;
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2769
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2770
            if (__diff >= 0) {
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2771
                __borrow = 0;
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2772
            } else {
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2773
                __borrow = 1;
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2774
                /* __diff += 0x10000; */
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2775
            }
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2776
            ((unsigned int *)(__resultDigits+__index-1))[0] = __diff;
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2777
            __index += 4;
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2778
        }
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2779
#endif /* alpha64 */
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2780
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2781
#if defined(i386) || defined(__LSBFIRST)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2782
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2783
         * subtract short-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2784
         */
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2785
        while (__index < __minLen) {   /* i.e. index+1 <= minLen */
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2786
            /* do not make this into one expression - ask cg why */
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2787
            __diff = ((unsigned short *)(__myDigits+__index-1))[0];
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2788
            __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2789
            __diff -= __borrow;
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2790
            if (__diff >= 0) {
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2791
                __borrow = 0;
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2792
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2793
                __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2794
                /* __diff += 0x10000; */
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2795
            }
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2796
            ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2797
            __index += 2;
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2798
        }
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2799
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2800
        if (__index == __minLen) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2801
            /* one of the operands has odd length - cannot continue short-wise */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2802
        } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2803
            if (__len1 > __len2) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2804
                while (__index < __len1) {
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2805
                    /* do not make this into one expression - ask cg why */
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2806
                    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2807
                    __diff -= __borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2808
                    if (__diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2809
                        __borrow = 0;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2810
                        ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2811
                        __index += 2;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2812
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2813
                        /* copy over rest */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2814
                        while (__index < __len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2815
                            ((unsigned short *)(__resultDigits+__index-1))[0] = ((unsigned short *)(__myDigits+__index-1))[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2816
                            __index+=2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2817
                        }
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2818
                        if (__index <= __len1) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2819
                            __resultDigits[__index-1] = __myDigits[__index-1];
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2820
                            __index++;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2821
                        }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2822
                        break;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2823
                    }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2824
                    __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2825
                    /* __diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2826
                    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2827
                    __index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2828
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2829
            } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2830
                if (__len2 > __len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2831
                    while (__index < __len2) {
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2832
                        /* do not make this into one expression - ask cg why */
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2833
                        __diff = 0;
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2834
                        __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2835
                        __diff -= __borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2836
                        if (__diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2837
                            __borrow = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2838
                        } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2839
                            __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2840
                            /* __diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2841
                        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2842
                        ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2843
                        __index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2844
                    }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2845
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2846
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2847
        }
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2848
#endif
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2849
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2850
         * subtract byte-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2851
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2852
        while (__index <= __minLen) {
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2853
            /* do not make this into one expression - ask cg why */
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2854
            __diff = __myDigits[__index-1];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2855
            __diff -= __otherDigits[__index-1];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2856
            __diff -= __borrow;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2857
            if (__diff >= 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2858
                __borrow = 0;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2859
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2860
                __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2861
                /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2862
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2863
            __resultDigits[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2864
            __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2865
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2866
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2867
        if (__len1 > __len2) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2868
            while (__index <= __len1) {
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2869
                /* do not make this into one expression - ask cg why */
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2870
                __diff = __myDigits[__index-1];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2871
                __diff -= __borrow;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2872
                if (__diff >= 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2873
                    __borrow = 0;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2874
                    /* copy over rest */
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2875
                    __resultDigits[__index-1] = __diff;
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2876
                    __index++;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2877
                    while (__index <= __len1) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2878
                        __resultDigits[__index-1] = __myDigits[__index-1];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2879
                        __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2880
                    }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2881
                    break;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2882
                }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2883
                __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2884
                /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2885
                __resultDigits[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2886
                __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2887
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2888
        } else {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2889
            if (__len2 > __len1) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2890
                while (__index <= __len2) {
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2891
                    /* do not make this into one expression - ask cg why */
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2892
                    __diff = 0;
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2893
                    __diff -= __otherDigits[__index-1];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2894
                    __diff -= __borrow;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2895
                    if (__diff >= 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2896
                        __borrow = 0;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2897
                    } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2898
                        __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2899
                        /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2900
                    }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2901
                    __resultDigits[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2902
                    __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2903
                }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2904
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2905
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2906
        borrow = __MKSMALLINT(__borrow);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2907
        index = __MKSMALLINT(__index);
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2908
        lastDigit = __MKSMALLINT(__resultDigits[__intVal(lResult)-1]);
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2909
    }
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2910
%}.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2911
    ok == true ifFalse:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2912
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2913
        borrow := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2914
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2915
        done := false.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2916
        [done] whileFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2917
            diff := borrow.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2918
            (index <= len1) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2919
                diff := diff + (digitByteArray basicAt:index).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2920
                (index <= len2) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2921
                    diff := diff - (otherDigitByteArray basicAt:index)
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2922
                ]
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2923
            ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2924
                (index <= len2) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2925
                    diff := diff - (otherDigitByteArray basicAt:index)
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2926
                ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2927
                    "end reached"
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2928
                    done := true
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2929
                ]
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2930
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2931
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2932
            "/ workaround for
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2933
            "/ gcc code generator bug
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2934
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2935
            (diff >= 0) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2936
                borrow := 0
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2937
            ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2938
                borrow := -1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2939
                diff := diff + 16r100
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2940
            ].
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2941
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2942
    "/        (diff < 0) ifTrue:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2943
    "/            borrow := -1.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2944
    "/            diff := diff + 16r100
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2945
    "/        ] ifFalse:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2946
    "/            borrow := 0
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2947
    "/        ].
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2948
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2949
            resultDigitByteArray basicAt:index put:diff.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2950
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2951
        ].
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2952
        lastDigit := resultDigitByteArray basicAt:lResult.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2953
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2954
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2955
    (borrow ~~ 0) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2956
        "/ must generate 255's complement
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2957
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2958
        result sign:-1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2959
        [index <= lResult] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2960
            resultDigitByteArray basicAt:index put:16rFF.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2961
            index := index + 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2962
        ].
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2963
        index := lResult.
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2964
        [index > 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2965
            resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2966
            index := index - 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2967
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2968
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2969
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2970
        carry := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2971
        [carry ~~ 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2972
            (index <= lResult) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2973
                carry := (resultDigitByteArray basicAt:index) + carry.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2974
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2975
            resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2976
            carry := carry bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2977
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2978
        ].
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2979
        lastDigit := resultDigitByteArray basicAt:lResult.
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2980
    ].
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2981
    (lastDigit ~~ 0 and:[lResult > SmallInteger maxBytes]) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2982
        ^ result
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2983
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2984
    ^ result compressed
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2985
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2986
    "Modified: 5.11.1996 / 14:09:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2987
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2988
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2989
absMod:anInteger
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2990
    "return a LargeIntegers representing
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2991
     abs(self) \\ abs(theArgument).
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2992
     Used as a helper for \\ and rem:"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2993
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2994
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2995
    |dividend divisor 
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2996
     shift "{ Class: SmallInteger }" |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2997
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2998
    anInteger == 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  2999
        ^ DivisionByZeroSignal raiseRequest
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3000
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3001
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3002
    self = anInteger ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3003
        ^ 0
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3004
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3005
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3006
    shift := self highBit - anInteger highBit.
4140
3e66cfaae7a7 Some fixes for absMod: on a negative number
Stefan Vogel <sv@exept.de>
parents: 4139
diff changeset
  3007
    dividend := self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3008
    shift < 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3009
        ^ dividend.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3010
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3011
    shift == 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3012
        divisor := anInteger simpleDeepCopy.
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3013
    ] ifFalse:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3014
        divisor := anInteger bitShift:shift.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3015
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3016
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3017
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3018
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3019
    [shift > 0] whileTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3020
        (dividend absLess:divisor) ifFalse:[
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3021
            (dividend absSubtract: divisor) ifFalse:[ "result == 0"
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3022
                ^ dividend compressed            
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3023
            ].
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3024
        ].
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3025
        shift := shift - 1.
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3026
        divisor div2.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3027
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3028
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3029
    ^ dividend compressed
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3030
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3031
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3032
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absMod:4000000001] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3033
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absDivMod:4000000001] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3034
     16000000000 absMod:4000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3035
     16000000000 absMod:3000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3036
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3037
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3038
    "Modified: / 5.11.1996 / 18:40:24 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3039
    "Created: / 27.4.1999 / 19:45:44 / stefan"
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3040
    "Modified: / 26.7.1999 / 10:46:18 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3041
!
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3042
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3043
absMul:aLargeInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3044
    "return a LargeInteger representing abs(self) * abs(theArgument)"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3045
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3046
    |result otherDigitByteArray resultDigitByteArray ok
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3047
     idx      "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3048
     carry    "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3049
     len1     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3050
     len2     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3051
     dstIndex "{ Class: SmallInteger }"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3052
     prod     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3053
     v        "{ Class: SmallInteger }"|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3054
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3055
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3056
    otherDigitByteArray := aLargeInteger digitBytes.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3057
    len2 := otherDigitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3058
4151
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
  3059
    result := LargeInteger basicNew numberOfDigits:(len1 + len2).
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3060
    resultDigitByteArray := result digitBytes.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3061
    ok := false.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3062
%{
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  3063
    if (__isByteArray(__INST(digitByteArray))
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3064
     && __isByteArray(otherDigitByteArray)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3065
     && __isByteArray(resultDigitByteArray)
250
a5deb61ffdac *** empty log message ***
claus
parents: 175
diff changeset
  3066
     && __bothSmallInteger(len1, len2)) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3067
        unsigned char *myBytes = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3068
        unsigned char *otherBytes = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3069
        unsigned char *resultBytes = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3070
        unsigned char *_p1, *_p2, *_pResult, *_pResult0, *_pResult1, *_p1Last, *_p2Last;
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3071
        unsigned char *_pResultLast1;
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3072
        unsigned INT _v;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3073
        int _len1 = __intVal(len1);
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3074
        int _len2 = __intVal(len2);
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3075
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3076
        _p1Last = myBytes    + _len1 - 1;  /* the last byte */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3077
        _p2Last = otherBytes + _len2 - 1;  /* the last byte */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3078
        _pResult0 = resultBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3079
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3080
        /*
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3081
         *        aaa...aaa      f1[0] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3082
         *       bbb...bbb       f1[1] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3083
         *      ccc...ccc        f1[2] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3084
         *     ...
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3085
         *    xxx...xxx          f1[high] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3086
         *
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3087
         * start short-wise
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3088
         * bounds: (16rFFFF * 16rFFFF) + 16rFFFF -> FFFF0000
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3089
         */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3090
        _p1 = myBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3091
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3092
#if defined(alpha64)
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3093
        /* loop over ints of f1 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3094
        for (; _p1 < _p1Last-2; _p1 += 4, _pResult0 += 4) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3095
            unsigned INT word1 = ((unsigned int *)_p1)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3096
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3097
            _pResult = _pResult0;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3098
            _p2 = otherBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3099
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3100
            /* loop over ints of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3101
            while (_p2 < (_p2Last-2)) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3102
                _v = (word1 * ((unsigned int *)_p2)[0]) + ((unsigned int *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3103
                ((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3104
                _v >>= 32; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3105
                _pResult += 4;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3106
                if (_v) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3107
                    unsigned char *_pResultLast3;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3108
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3109
                    /* distribute carry - int-wise, then byte-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3110
                    _pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3111
                    for (_pResult1 = _pResult; _v; _pResult1 += 4) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3112
                        if (_pResult1 > _pResultLast3) break;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3113
                        _v += ((unsigned int *)_pResult1)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3114
                        ((unsigned int *)_pResult1)[0] = _v /* & 0xFFFFFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3115
                        _v >>= 32;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3116
                    }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3117
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3118
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3119
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3120
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3121
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3122
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3123
                _p2 += 4;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3124
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3125
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3126
            /* possible odd highByte of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3127
            while (_p2 <= _p2Last) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3128
                _v = (word1 * _p2[0]) + ((unsigned int *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3129
                ((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3130
                _v >>= 32; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3131
                _pResult += 4;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3132
                if (_v) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3133
                    unsigned char *_pResultLast3;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3134
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3135
                    /* distribute carry - int-wise, then byte-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3136
                    _pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3137
                    for (_pResult1 = _pResult; _v; _pResult1 += 4) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3138
                        if (_pResult1 > _pResultLast3) break;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3139
                        _v += ((unsigned int *)_pResult1)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3140
                        ((unsigned int *)_pResult1)[0] = _v /* & 0xFFFFFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3141
                        _v >>= 32;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3142
                    }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3143
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3144
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3145
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3146
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3147
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3148
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3149
                _p2++;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3150
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3151
        }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3152
#endif /* alpha64 */
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3153
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3154
        /* loop over shorts of f1 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3155
        for (; _p1 < _p1Last; _p1 += 2, _pResult0 += 2) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3156
            unsigned int short1 = ((unsigned short *)_p1)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3157
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3158
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3159
            short1 = ((short1 >> 8) & 0xFF) | ((short1 & 0xFF) << 8);
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3160
#endif
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3161
            _pResult = _pResult0;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3162
            _p2 = otherBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3163
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3164
            /* loop over shorts of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3165
            while (_p2 < _p2Last) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3166
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3167
                unsigned int _short2;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3168
                unsigned int _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3169
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3170
                _short2 = ((unsigned short *)_p2)[0];
4268
506e49eb659b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4266
diff changeset
  3171
                _short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3172
                _short3 = ((unsigned short *)_pResult)[0];
4268
506e49eb659b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4266
diff changeset
  3173
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3174
                _v = (short1 * _short2) + _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3175
                _pResult[0] = _v;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3176
                _pResult[1] = _v >> 8;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3177
#else /* LSBFIRST */
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3178
                _v = (short1 * ((unsigned short *)_p2)[0]) + ((unsigned short *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3179
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3180
#endif
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3181
                _v >>= 16; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3182
                _pResult += 2;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3183
                if (_v) {
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3184
                    /* distribute carry - short-wise, then byte-wise */
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3185
                    _pResult1 = _pResult;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3186
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)  
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3187
                    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3188
                    for (; _v; _pResult1 += 2) {
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3189
                        if (_pResult1 > _pResultLast1) break;
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3190
                        _v += ((unsigned short *)_pResult1)[0];
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3191
                        ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3192
                        _v >>= 16;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3193
                    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3194
#endif
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3195
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3196
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3197
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3198
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3199
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3200
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3201
                _p2 += 2;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3202
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3203
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3204
            /* possible odd highByte of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3205
            if (_p2 <= _p2Last) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3206
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3207
                unsigned int _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3208
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3209
                _short3 = ((unsigned short *)_pResult)[0];
4268
506e49eb659b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4266
diff changeset
  3210
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3211
                _v = (short1 * _p2[0]) + _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3212
                _pResult[0] = _v;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3213
                _pResult[1] = _v >> 8;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3214
#else /* LSBFIRST */
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3215
                _v = (short1 * _p2[0]) + ((unsigned short *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3216
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3217
#endif
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3218
                _v >>= 16; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3219
                _pResult += 2;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3220
                if (_v) {
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3221
                    /* distribute carry - short-wise, then byte-wise */
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3222
                    _pResult1 = _pResult;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3223
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)  
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3224
                    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3225
                    for (; _v; _pResult1 += 2) {
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3226
                        if (_pResult1 > _pResultLast1) break;
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3227
                        _v += ((unsigned short *)_pResult1)[0];
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3228
                        ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3229
                        _v >>= 16;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3230
                    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3231
#endif
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3232
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3233
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3234
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3235
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3236
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3237
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3238
                _p2++;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3239
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3240
        }
4164
59da946fb307 oops - the short-multiply optimization is only ok
Claus Gittinger <cg@exept.de>
parents: 4163
diff changeset
  3241
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3242
        /* possible odd highByte of f1 (or byteLoop, if not LSBFIRST) */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3243
        for (; _p1 <= _p1Last; _p1++, _pResult0++) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3244
            unsigned int byte1 = _p1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3245
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3246
            _pResult = _pResult0;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3247
            _p2 = otherBytes;
4175
ecbeb3109903 fixed absMul: (for non-LSBFIRST)
Claus Gittinger <cg@exept.de>
parents: 4174
diff changeset
  3248
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3249
            /* loop over shorts of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3250
            while (_p2 < _p2Last) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3251
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3252
                unsigned int _short2;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3253
                unsigned int _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3254
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3255
                _short2 = ((unsigned short *)_p2)[0];
4268
506e49eb659b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4266
diff changeset
  3256
                _short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3257
                _short3 = ((unsigned short *)_pResult)[0];
4268
506e49eb659b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4266
diff changeset
  3258
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3259
                _v = (byte1 * _short2) + _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3260
                _pResult[0] = _v;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3261
                _pResult[1] = _v >> 8;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3262
#else /* LSBFIRST */
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3263
                _v = (byte1 * ((unsigned short *)_p2)[0]) + ((unsigned short *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3264
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3265
#endif
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3266
                _v >>= 16; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3267
                _pResult += 2;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3268
                if (_v) {
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3269
                    /* distribute carry - short-wise, then byte-wise */
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3270
                    _pResult1 = _pResult;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3271
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3272
                    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3273
                    for (_pResult1 = _pResult; _v; _pResult1 += 2) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3274
                        if (_pResult1 > _pResultLast1) break;
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3275
                        _v += ((unsigned short *)_pResult1)[0];
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3276
                        ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3277
                        _v >>= 16;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3278
                    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3279
#endif /* __LSBFIRST */
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3280
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3281
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3282
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3283
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3284
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3285
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3286
                _p2 += 2;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3287
            }
4164
59da946fb307 oops - the short-multiply optimization is only ok
Claus Gittinger <cg@exept.de>
parents: 4163
diff changeset
  3288
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3289
            /* possible odd highByte of f2 (or byteLoop, if not LSBFIRST) */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3290
            while (_p2 <= _p2Last) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3291
                _v = (byte1 * _p2[0]) + _pResult[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3292
                _pResult[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3293
                _v >>= 8; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3294
                _pResult++;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3295
                if (_v) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3296
                    /* distribute carry */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3297
                    for (_pResult1 = _pResult; _v; _pResult1++) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3298
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3299
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3300
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3301
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3302
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3303
                _p2++;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3304
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3305
        }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3306
        ok = true;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3307
    }
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3308
%}.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3309
    ok ifFalse:[
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3310
        1 to:len1 do:[:index1 |
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3311
            1 to:len2 do:[:index2 |
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3312
                dstIndex := index1 + index2 - 1.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3313
                prod := (digitByteArray basicAt:index1) * (otherDigitByteArray basicAt:index2).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3314
                prod := prod + (resultDigitByteArray basicAt:dstIndex).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3315
                resultDigitByteArray basicAt:dstIndex put:(prod bitAnd:16rFF).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3316
                carry := prod bitShift:-8.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3317
                carry ~~ 0 ifTrue:[
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3318
                    idx := dstIndex + 1.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3319
                    [carry ~~ 0] whileTrue:[
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3320
                        v := (resultDigitByteArray basicAt:idx) + carry.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3321
                        resultDigitByteArray basicAt:idx put:(v bitAnd:255).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3322
                        carry := v bitShift:-8.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3323
                        idx := idx + 1
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3324
                    ]
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3325
                ]
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3326
            ]
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3327
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3328
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3329
    ^ result compressed
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3330
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3331
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3332
absPlus:aLargeInteger sign:newSign
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3333
    "return a LargeInteger representing abs(self) + abs(theArgument)
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3334
     with sign: newSign.
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3335
     The result is normalized. The argument must be a smallInteger
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3336
     with byteSize one less than the integer byteSize.
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3337
     This is a helper for addition and subtraction - not for public use."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3338
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3339
    |result done otherDigitByteArray resultDigitByteArray
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3340
     len1   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3341
     len2   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3342
     newLen "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3343
     index  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3344
     carry  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3345
     sum    "{ Class: SmallInteger }" |
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3346
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3347
    otherDigitByteArray := aLargeInteger digitBytes.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3348
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3349
%{
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3350
    OBJ _digitByteArray = __INST(digitByteArray);
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3351
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3352
    if (__isByteArray(_digitByteArray)
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3353
     && __isByteArray(otherDigitByteArray)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3354
        int _len1, _len2, _newLen;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3355
        unsigned char *_myDigits, *_otherDigits, *_newDigits;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3356
        int _index, _carry;
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3357
        int _comLen;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3358
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3359
        _len1 = __byteArraySize(_digitByteArray);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3360
        _len2 = __byteArraySize(otherDigitByteArray);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3361
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3362
        _otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3363
        _myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3364
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3365
        if (_len1 < _len2) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3366
            _comLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3367
            _newLen = _len2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3368
            if (_otherDigits[_len2 - 1] == 0xFF) _newLen++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3369
        } else if (_len2 < _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3370
            _comLen = _len2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3371
            _newLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3372
            if (_myDigits[_len1 - 1] == 0xFF) _newLen++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3373
        } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3374
            /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3375
             * there can only be an overflow from the high bytes,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3376
             * if their sum is >= 255
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3377
             * (with sum==255, a carry could still occur from the next lower bytes)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3378
             */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3379
            _newLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3380
            if ((_otherDigits[_len2 - 1] + _myDigits[_len1 - 1]) >= 0xFF) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3381
                _newLen++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3382
            } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3383
                if (_newLen == sizeof(INT)) {
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3384
                    OBJ _uint;
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3385
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3386
                    /* 
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3387
                     * two word-sized numbers, no carry - a very common case ...
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3388
                     */
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3389
#if defined(__LSB_FIRST) || defined(i386) || defined(alpha)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3390
                    unsigned INT _sum = *(unsigned INT *)_otherDigits + *(unsigned INT *)_myDigits;
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3391
#else
5002
e895e251d501 __longIntVal has been renamed to __unsignedLongIntVal
Stefan Vogel <sv@exept.de>
parents: 5000
diff changeset
  3392
                    unsigned INT _sum = __unsignedLongIntVal(self) + __unsignedLongIntVal(aLargeInteger);
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3393
#endif /* not LSB_FIRST */
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3394
                    _uint = __MKUINT(_sum);
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3395
                    if (!__isSmallInteger(_uint))
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3396
                        __LargeIntegerInstPtr(_uint)->l_sign = newSign;
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3397
                    RETURN (_uint);
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3398
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3399
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3400
            _comLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3401
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3402
        resultDigitByteArray = __BYTEARRAY_UNINITIALIZED_NEW_INT(_newLen);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3403
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3404
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3405
         * must refetch - GC could have been invoked
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3406
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3407
        _digitByteArray = __INST(digitByteArray);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3408
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3409
        _myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3410
        _otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3411
        _newDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3412
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3413
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3414
         * add them ...
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3415
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3416
        _index = 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3417
        _carry = 0;
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3418
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3419
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3420
# if 0 && defined(alpha64) && defined(__GNUC__)
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3421
        {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3422
            int _comLen7;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3423
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3424
            /*
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3425
             * have a 64bit integers;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3426
             * add quad-wise
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3427
             * accessing bytes at: [index-1][index][index+1]..[index+6]
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3428
             */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3429
            _comLen7 = _comLen - 3 - 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3430
            while (_index <= _comLen7) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3431
                UINT64 _sum, _t1, _t2;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3432
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3433
                asm ("addq   %5,%6,%1         \n     /* sum */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3434
                      addq   %0,%1,%1         \n     /* plus carryIn */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3435
                      cmpult %1,%5,%2         \n     /* was there a carry ? */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3436
                      cmpult %1,%6,%3         \n     /* was there a carry ? */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3437
                      bis    %2,%3,%0         \n     /* carryOut */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3438
                     "    
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3439
                        : "=r"  (_carry),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3440
                          "=r"  (_sum),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3441
                          "r"   (_t1),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3442
                          "r"   (_t2)
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3443
                        : "r"   (_carry),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3444
                          "r"   (((unsigned long *)(&(_myDigits[_index - 1])))[0]), 
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3445
                          "r"   (((unsigned long *)(&(_otherDigits[_index - 1])))[0])
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3446
                    );
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3447
                /* _sum = _sum & 0xFFFFFFFF; */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3448
                ((unsigned long *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3449
                _index += 8;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3450
            }
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3451
        }
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3452
# endif /* alpha64 */
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3453
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
  3454
# if 0 && defined(alpha64)      /* not faster */
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3455
        {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3456
            int _comLen7;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3457
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3458
            /*
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3459
             * have a 64bit integers;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3460
             * add quad-wise
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3461
             * accessing bytes at: [index-1][index][index+1]..[index+6]
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3462
             */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3463
            _comLen7 = _comLen - 3 - 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3464
            while (_index <= _comLen7) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3465
                UINT64 _sum, _t1, _t2;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3466
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3467
                _t1 = ((UINT64 *)(&(_myDigits[_index - 1])))[0];
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3468
                _t2 = ((UINT64 *)(&(_otherDigits[_index - 1])))[0];
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3469
                _sum = _t1 + _t2 + _carry;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3470
                ((UINT64 *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3471
                _carry = (_sum < _t1) | (_sum < _t2);
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3472
                _index += 8;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3473
            }
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3474
        }
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3475
# endif /* alpha64 */
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3476
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3477
# ifdef UINT64
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3478
        {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3479
            int _comLen3;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3480
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3481
            /*
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3482
             * have a 64bit integer type;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3483
             * add int-wise
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3484
             * accessing bytes at: [index-1][index][index+1][index+2]
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3485
             */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3486
            _comLen3 = _comLen - 3;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3487
            while (_index <= _comLen3) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3488
                UINT64 _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3489
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3490
                _sum = _carry
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3491
                        + *(unsigned *)(&(_myDigits[_index - 1]))
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3492
                        + *(unsigned *)(&(_otherDigits[_index - 1]));
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3493
                _carry = _sum >> 32;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3494
                /* _sum = _sum & 0xFFFFFFFF; */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3495
                ((unsigned int *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3496
                _index += 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3497
            }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3498
        }
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3499
# else
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3500
#  if defined(i386) && defined(__GNUC__)
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3501
        {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3502
            int _comLen3;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3503
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3504
            _comLen3 = _comLen - 3 - 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3505
            while (_index <= _comLen3) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3506
                unsigned int _sum, _sum2;
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3507
                unsigned int __in1A, __in1B, __in2A, __in2B;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3508
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3509
                __in1A = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3510
                __in2A = ((unsigned int *)(&(_myDigits[_index - 1])))[1];
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3511
                __in1B = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3512
                __in2B = ((unsigned int *)(&(_otherDigits[_index - 1])))[1];
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3513
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3514
                asm ("addl %%edx,%%eax         
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3515
                      movl $0,%%edx            
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3516
                      adcl $0,%%edx            
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3517
                      addl %5,%%eax            
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3518
                      adcl $0,%%edx
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3519
4283
cb0eee96df13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4282
diff changeset
  3520
                      addl %%edx,%%ecx  
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3521
                      movl $0,%%edx            
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3522
                      adcl $0,%%edx            
4283
cb0eee96df13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4282
diff changeset
  3523
                      addl %7,%%ecx            
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3524
                      adcl $0,%%edx
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3525
                     "    
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3526
                        : "=d"  (_carry),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3527
                          "=a"  (_sum),
4283
cb0eee96df13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4282
diff changeset
  3528
                          "=c"  (_sum2)
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3529
                        : "0"   (_carry),
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3530
                          "1"   (__in1A), 
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3531
                          "rm"  (__in1B), 
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3532
                          "2"   (__in2A), 
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3533
                          "rm"  (__in2B) 
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3534
                    );
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3535
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3536
                ((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3537
                ((unsigned *)(&(_newDigits[_index - 1])))[1] = _sum2;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3538
                _index += 8;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3539
            }
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3540
            /*
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3541
             * add int-wise
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3542
             * accessing bytes at: [index-1][index][index+1][index+2]
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3543
             */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3544
            _comLen3 = _comLen3 + 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3545
            if (_index <= _comLen3) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3546
                unsigned int _sum;
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3547
                unsigned int __inA, __inB;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3548
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3549
                __inA = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3550
                __inB = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3551
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3552
                asm ("addl %%edx,%%eax      \n   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3553
                      movl $0,%%edx         \n   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3554
                      adcl $0,%%edx         \n   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3555
                      addl %4,%%eax         \n   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3556
                      adcl $0,%%edx"    
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3557
                        : "=d"  (_carry),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3558
                          "=a"  (_sum)
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3559
                        : "0"   (_carry),
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3560
                          "1"   (__inA), 
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3561
                          "rm"  (__inB) 
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3562
                    );
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3563
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3564
                ((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3565
                _index += 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3566
            }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3567
        }
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3568
#  endif /* i386 && GNUC */
4276
e521248cbb88 tuned large + large on win32
Claus Gittinger <cg@exept.de>
parents: 4270
diff changeset
  3569
#  if defined(i386) && defined(WIN32)
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3570
        {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3571
            int _comLen3;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3572
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3573
            /*
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3574
             * add long-wise
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3575
             * accessing bytes at: [index-1][index][index+1][index+2]
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3576
             */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3577
            _comLen3 = _comLen - 3;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3578
            while (_index <= _comLen3) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3579
                unsigned int _sum, _v1, _v2;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3580
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3581
                _v1 = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3582
                _v2 = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3583
                asm { 
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3584
                      mov eax, _v1   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3585
                      add eax, _v2   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3586
                      mov edx, 0
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3587
                      adc edx, 0
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3588
                      add eax, _carry   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3589
                      adc edx, 0
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3590
                      mov _carry, edx
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3591
                      mov _sum, eax
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3592
                    }
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3593
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3594
                ((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3595
                _index += 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3596
            }
4276
e521248cbb88 tuned large + large on win32
Claus Gittinger <cg@exept.de>
parents: 4270
diff changeset
  3597
        }
e521248cbb88 tuned large + large on win32
Claus Gittinger <cg@exept.de>
parents: 4270
diff changeset
  3598
#  endif /* i386 && WIN32 */
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3599
# endif / INT64 */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3600
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3601
         * add short-wise
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3602
         * accessing bytes at: [index-1][index]
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3603
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3604
        while (_index < _comLen) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3605
            unsigned int _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3606
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3607
            _sum = _carry 
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3608
                   + ((unsigned short *)(&(_myDigits[_index - 1])))[0]
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3609
                   + ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3610
            _carry = _sum >> 16;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3611
            /* _sum = _sum & 0xFFFF; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3612
            *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3613
            _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3614
        }
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3615
#else
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3616
# ifdef sparc
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3617
        /*
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3618
         * add short-wise
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3619
         * accessing bytes at: [index-1][index]
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3620
         */
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3621
        while (_index < _comLen) {
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3622
            unsigned int _sum;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3623
            unsigned short _v1, _v2;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3624
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3625
            _v1 = ((unsigned short *)(&(_myDigits[_index - 1])))[0];
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3626
            _v2 = ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3627
            _sum = _carry + (_v1>>8) + (_v2>>8);
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3628
            _carry = _sum >> 8;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3629
            _newDigits[_index - 1] = _sum;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3630
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3631
            _sum = _carry + (_v1 & 0xFF) + (_v2 & 0xFF);
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3632
            _carry = _sum >> 8;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3633
            _newDigits[_index] = _sum;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3634
            _index += 2;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3635
        }
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3636
# endif
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
  3637
#endif /* __LSBFIRST */
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  3638
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3639
        /*
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3640
         * add byte-wise
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3641
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3642
        while (_index <= _comLen) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3643
            unsigned int _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3644
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3645
            _sum = _carry 
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3646
                   + _myDigits[_index - 1] 
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3647
                   + _otherDigits[_index - 1];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3648
            _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3649
            /* _sum = _sum & 0xFF; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3650
            _newDigits[_index - 1] = _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3651
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3652
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3653
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3654
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3655
         * rest
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3656
         */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3657
        if (_len1 > _len2) {
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3658
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3659
            if (_index <= _len1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3660
                if ((_index - 1) & 1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3661
                    /* odd byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3662
                    unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3663
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3664
                    _sum = _carry + _myDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3665
                    _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3666
                    /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3667
                    _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3668
                    _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3669
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3670
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3671
                while (_index < _len1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3672
                    /* shorts */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3673
                    unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3674
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3675
                    _sum = _carry + *(unsigned short *)(&(_myDigits[_index - 1]));
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3676
                    _carry = _sum >> 16;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3677
                    /* _sum = _sum & 0xFFFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3678
                    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3679
                    _index += 2;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3680
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3681
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3682
                if (_index <= _len1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3683
                    /* last byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3684
                    unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3685
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3686
                    _sum = _carry + _myDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3687
                    _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3688
                    /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3689
                    _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3690
                    _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3691
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3692
            }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3693
#else
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3694
            while (_index <= _len1) {
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3695
                unsigned int _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3696
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3697
                _sum = _carry + _myDigits[_index - 1];
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3698
                _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3699
                /* _sum = _sum & 0xFF; */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3700
                _newDigits[_index - 1] = _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3701
                _index++;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3702
            }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3703
#endif /* not LSB */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3704
        } else {
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3705
            if (_len2 > _len1) {
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3706
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3707
                if (_index <= _len2) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3708
                    if ((_index - 1) & 1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3709
                        /* odd byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3710
                        unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3711
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3712
                        _sum = _carry + _otherDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3713
                        _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3714
                        /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3715
                        _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3716
                        _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3717
                    }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3718
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3719
                    while (_index < _len2) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3720
                        /* shorts */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3721
                        unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3722
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3723
                        _sum = _carry + *(unsigned short *)(&(_otherDigits[_index - 1]));
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3724
                        _carry = _sum >> 16;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3725
                        /* _sum = _sum & 0xFFFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3726
                        *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3727
                        _index += 2;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3728
                    }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3729
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3730
                    if (_index <= _len2) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3731
                        /* last byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3732
                        unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3733
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3734
                        _sum = _carry + _otherDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3735
                        _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3736
                        /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3737
                        _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3738
                        _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3739
                    }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3740
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3741
#else
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3742
                while (_index <= _len2) {
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3743
                    unsigned int _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3744
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3745
                    _sum = _carry + _otherDigits[_index - 1];
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3746
                    _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3747
                    /* _sum = _sum & 0xFF; */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3748
                    _newDigits[_index - 1] = _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3749
                    _index++;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3750
                }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3751
#endif /* not LSB */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3752
            }
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3753
        }
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3754
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3755
        while (_index <= _newLen) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3756
            unsigned int _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3757
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3758
            _sum = _carry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3759
            _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3760
            /* _sum = _sum & 0xFF; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3761
            _newDigits[_index - 1] = _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3762
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3763
        }
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3764
    }
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3765
%}.
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3766
    resultDigitByteArray notNil ifTrue:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3767
        result := self class basicNew.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3768
        result setDigits:resultDigitByteArray.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3769
        result sign:newSign.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3770
    ] ifFalse:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3771
        len1 := digitByteArray size.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3772
        len2 := otherDigitByteArray size.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3773
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3774
        "/ earlier versions estimated the newLength as:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3775
        "/ (len1 max:len2) + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3776
        "/ and reduced the result.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3777
        "/ however, if one of the addends is smaller,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3778
        "/ the result will never require another digit,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3779
        "/ if the highest digit of the larger addent is
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3780
        "/ not equal to 255. Therefore, in most cases,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3781
        "/ we can avoid the computation and resizing 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3782
        "/ in #reduced.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3783
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3784
        len1 < len2 ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3785
            newLen := len2.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3786
            (otherDigitByteArray at:len2) == 16rFF ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3787
                newLen := newLen + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3788
            ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3789
        ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3790
            len2 < len1 ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3791
                newLen := len1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3792
                (digitByteArray at:len1) == 16rFF ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3793
                    newLen := newLen + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3794
                ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3795
            ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3796
                newLen := len1 + 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3797
            ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3798
        ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3799
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3800
        result := self class basicNew numberOfDigits:newLen.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3801
        result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3802
        resultDigitByteArray := result digitBytes.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3803
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3804
        index := 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3805
        carry := 0.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3806
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3807
        done := false.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3808
        [done] whileFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3809
            sum := carry.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3810
            (index <= len1) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3811
                sum := sum + (digitByteArray basicAt:index).
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3812
                (index <= len2) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3813
                    sum := sum + (otherDigitByteArray basicAt:index)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3814
                ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3815
            ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3816
                (index <= len2) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3817
                    sum := sum + (otherDigitByteArray basicAt:index)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3818
                ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3819
                    "end reached"
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3820
                    done := true
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3821
                ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3822
            ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3823
            (sum >= 16r100) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3824
                carry := 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3825
                sum := sum - 16r100
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3826
            ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3827
                carry := 0
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3828
            ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3829
            resultDigitByteArray basicAt:index put:sum.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3830
            index := index + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3831
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3832
    ].
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3833
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3834
    ^ result compressed
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3835
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3836
    "Modified: 11.8.1997 / 03:23:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3837
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3838
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3839
absSubtract:aLargeInteger
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3840
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3841
        destructively subtract aLargeInteger from myself
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3842
        AND return true, if the result is non-zero, false otherwise.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3843
        (i.e. this method has both a return value and a side-effect
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3844
         on the receiver)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3845
        Only allowed for positive receiver and argument
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3846
        The receiver must be >= the argument.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3847
        The receiver must be a temporary scratch-number"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3848
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3849
    |otherDigitByteArray
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3850
     len1   "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3851
     len2   "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3852
     index  "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3853
     borrow "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3854
     diff   "{ Class: SmallInteger }"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3855
     notZero
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3856
    |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3857
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3858
    notZero := false.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3859
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3860
    otherDigitByteArray := aLargeInteger digitBytes.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3861
    len2 := otherDigitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3862
    len2 > len1 ifTrue:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3863
        [(otherDigitByteArray at:len2) == 0] whileTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3864
            len2 := len2 - 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3865
        ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3866
        len2 > len1 ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3867
            self halt "/ may not be called that way
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3868
        ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3869
    ].
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3870
    "/ knowing that len2 is <= len1
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3871
%{
4189
Claus Gittinger <cg@exept.de>
parents: 4188
diff changeset
  3872
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3873
    OBJ _digitByteArray = __INST(digitByteArray);
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3874
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3875
    if (__isByteArray(_digitByteArray)
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3876
     && __isByteArray(otherDigitByteArray)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3877
        int _len1 = __intVal(len1), 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3878
            _len2 = __intVal(len2);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3879
        unsigned char *_myDigits, *_otherDigits;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3880
        int _index = 1, _borrow = 0;
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3881
        INT _diff;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3882
        INT anyBitNonZero = 0;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3883
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3884
        _otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3885
        _myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3886
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3887
#if defined(alpha64)
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3888
        {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3889
            int _len2Q;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3890
            /*
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3891
             * subtract int-wise
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3892
             */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3893
            _len2Q = _len2-2;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3894
            while (_index < _len2Q) {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3895
                /* do not combine the expression below (may lead to unsigned result on some machines */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3896
                _diff = ((unsigned int *)(_myDigits+_index-1))[0];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3897
                _diff -= ((unsigned int *)(_otherDigits+_index-1))[0];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3898
                _diff -= _borrow;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3899
                if (_diff >= 0) {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3900
                    _borrow = 0;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3901
                } else {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3902
                    _borrow = 1;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3903
                    /* _diff += 0x10000; */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3904
                }
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3905
                ((unsigned int *)(_myDigits+_index-1))[0] = _diff;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3906
                anyBitNonZero |= (_diff & 0xFFFFFFFFL);
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3907
                _index += 4;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3908
            }
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3909
        }
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3910
#endif
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3911
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3912
#if defined(i386) || defined(__LSBFIRST)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3913
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3914
         * subtract short-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3915
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3916
        while (_index < _len2) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3917
            /* do not combine the expression below (may lead to unsigned result on some machines */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3918
            _diff = ((unsigned short *)(_myDigits+_index-1))[0];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3919
            _diff -= ((unsigned short *)(_otherDigits+_index-1))[0];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3920
            _diff -= _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3921
            if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3922
                _borrow = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3923
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3924
                _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3925
                /* _diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3926
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3927
            ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3928
            anyBitNonZero |= (_diff & 0xFFFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3929
            _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3930
        }
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3931
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3932
        if (_index <= _len2) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3933
            /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3934
             * cannot continue with shorts - there is an odd number of
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3935
             * bytes in the minuent
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3936
             */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3937
        } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3938
            while (_index < _len1) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3939
                /* do not combine the expression below (may lead to unsigned result on some machines */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3940
                _diff = ((unsigned short *)(_myDigits+_index-1))[0];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3941
                _diff -= _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3942
                if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3943
                    /* _borrow = 0; */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3944
                    ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3945
                    anyBitNonZero |= (_diff & 0xFFFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3946
                    _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3947
                    while (_index < _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3948
                        anyBitNonZero |= ((unsigned short *)(_myDigits+_index-1))[0];
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3949
                        if (anyBitNonZero) {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3950
                            RETURN (true);
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3951
                        }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3952
                        _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3953
                    }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3954
                    /* last odd index */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3955
                    if (_index <= _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3956
                        anyBitNonZero |= _myDigits[_index - 1];;
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3957
                        if (anyBitNonZero) {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3958
                            RETURN (true);
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3959
                        }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3960
                        _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3961
                    }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3962
                    RETURN (anyBitNonZero ? true : false);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3963
                }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3964
                _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3965
                /* _diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3966
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3967
                ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3968
                anyBitNonZero |= (_diff & 0xFFFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3969
                _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3970
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3971
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3972
#endif
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3973
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3974
         * subtract byte-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3975
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3976
        while (_index <= _len2) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3977
            /* do not combine the expression below (may lead to unsigned result on some machines */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3978
            _diff = _myDigits[_index - 1];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3979
            _diff -= _otherDigits[_index - 1];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3980
            _diff -= _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3981
            if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3982
                _borrow = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3983
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3984
                _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3985
                /* _diff += 0x100; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3986
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3987
            _myDigits[_index - 1] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3988
            anyBitNonZero |= (_diff & 0xFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3989
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3990
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3991
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3992
        while (_index <= _len1) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3993
            /* do not combine the expression below (may lead to unsigned result on some machines */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3994
            _diff = _myDigits[_index - 1];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3995
            _diff -= _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3996
            if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3997
                /* _borrow = 0; */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3998
                _myDigits[_index - 1] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3999
                anyBitNonZero |= (_diff & 0xFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4000
                _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4001
                while (_index <= _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4002
                    anyBitNonZero |= _myDigits[_index - 1];
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4003
                    if (anyBitNonZero) {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4004
                        RETURN (true);
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4005
                    }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4006
                    _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4007
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4008
                break;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4009
            }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  4010
            _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  4011
            /* _diff += 0x100; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4012
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4013
            _myDigits[_index - 1] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4014
            anyBitNonZero |= (_diff & 0xFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4015
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4016
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4017
        RETURN (anyBitNonZero ? true : false);
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4018
    }
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4019
%}.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4020
    self halt:'should not happen'.
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4021
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4022
"/    index := 1.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4023
"/    borrow := 0.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4024
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4025
"/    [index <= len1] whileTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4026
"/        diff := borrow.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4027
"/        diff := diff + (digitByteArray basicAt:index).
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4028
"/        index <= len2 ifTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4029
"/            diff := diff - (otherDigitByteArray basicAt:index).
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4030
"/        ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4031
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4032
"/        "/ workaround for
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4033
"/        "/ gcc code generator bug
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4034
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4035
"/        (diff >= 0) ifTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4036
"/            borrow := 0
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4037
"/        ] ifFalse:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4038
"/            borrow := -1.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4039
"/            diff := diff + 16r100
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4040
"/        ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4041
"/        diff ~~ 0 ifTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4042
"/            notZero := true
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4043
"/        ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4044
"/        digitByteArray basicAt:index put:diff.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4045
"/        index := index + 1
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4046
"/    ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4047
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4048
"/    ^ notZero
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4049
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4050
    "Created: / 5.11.1996 / 16:23:47 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4051
    "Modified: / 5.11.1996 / 18:56:50 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4052
    "Modified: / 27.4.1999 / 18:08:23 / stefan"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4053
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4054
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4055
div2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4056
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4057
       destructively divide the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4058
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4059
%{  /* NOCONTEXT */
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4060
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4061
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4062
    if (__isByteArray(__digits)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4063
        int __nBytes = __byteArraySize(__digits);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4064
        unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4065
        unsigned INT __this, __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4066
        int __idx;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4067
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4068
        if (__nBytes == 1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4069
            __bp[0] >>= 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4070
            RETURN (self);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4071
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4072
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4073
        __idx = 1;
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4074
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4075
#if defined(alpha64)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4076
        if (sizeof(unsigned INT) == 8) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4077
            int __endIndex = __nBytes - 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4078
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4079
            if (__idx < __endIndex) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4080
                __this = ((unsigned INT *)__bp)[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4081
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4082
                while (__idx < __endIndex) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4083
                    __next = ((unsigned INT *)__bp)[1];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4084
                    __this = (__this >> 1) /* & 0x7FFFFFFFFFFFFFF */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4085
                    __this |= __next << 63;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4086
                    ((unsigned INT *)__bp)[0] = __this;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4087
                    __this = __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4088
                    __bp += 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4089
                    __idx += 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4090
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4091
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4092
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4093
#else
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4094
# if defined(__LSBFIRST) || defined(i386) 
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4095
        if (sizeof(unsigned int) == 4) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4096
            int __endIndex = __nBytes - 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4097
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4098
            if (__idx < __endIndex) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4099
                __this = ((unsigned INT *)__bp)[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4100
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4101
                while (__idx < __endIndex) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4102
                    __next = ((unsigned int *)__bp)[1];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4103
                    __this = (__this >> 1) /* & 0x7FFFFFF */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4104
                    __this |= __next << 31;
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4105
                    ((unsigned int *)__bp)[0] = __this;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4106
                    __this = __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4107
                    __bp += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4108
                    __idx += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4109
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4110
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4111
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4112
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  4113
#endif
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4114
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4115
        __this = __bp[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4116
        while (__idx < __nBytes) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4117
            __next = __bp[1];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4118
            __this >>= 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4119
            __this |= __next << 7;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4120
            __bp[0] = __this;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4121
            __this = __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4122
            __bp++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4123
            __idx++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4124
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4125
        __bp[0] = __this >> 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4126
        RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4127
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4128
%}.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4129
    self primitiveFailed
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4130
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4131
    "
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4132
     100000 asLargeInteger div2      
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4133
     1000000000000000000000000000 div2 
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4134
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4135
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4136
    "Modified: 5.11.1996 / 16:12:56 / cg"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4137
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4138
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4139
mul2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4140
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4141
       destructively multiply the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4142
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4143
    |nBytes "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4144
     b      "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4145
     t|
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4146
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4147
    nBytes := digitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4148
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4149
    b := digitByteArray at:nBytes.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4150
    (b bitAnd:16r80) ~~ 0 ifTrue:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4151
        "/ need another byte
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4152
        nBytes := nBytes + 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4153
        t := ByteArray uninitializedNew:nBytes.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4154
        t replaceFrom:1 to:nBytes-1 with:digitByteArray startingAt:1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4155
        t at:nBytes put:0.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4156
        digitByteArray := t.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4157
    ].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4158
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4159
%{
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4160
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4161
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4162
    if (__isByteArray(__digits)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4163
        int __nBytes = __intVal(nBytes);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4164
        unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4165
        unsigned INT __carry = 0, __newCarry,  __this;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4166
        int __idx;
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4167
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4168
#if defined(alpha64)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4169
        if (sizeof(unsigned INT) == 8) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4170
            while (__nBytes >= 8) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4171
                __this = ((unsigned INT *)__bp)[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4172
                __newCarry = (__this >> 63) /* & 1 */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4173
                ((unsigned INT *)__bp)[0] = (__this << 1) | __carry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4174
                __carry = __newCarry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4175
                __bp += 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4176
                __nBytes -= 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4177
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4178
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4179
#else
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4180
# if defined(__LSBFIRST) || defined(i386) /* XXX actually: LSB_FIRST */
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4181
        if (sizeof(unsigned int) == 4) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4182
            while (__nBytes >= 4) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4183
                __this = ((unsigned int *)__bp)[0];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4184
                __newCarry = (__this >> 31) /* & 1 */;
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4185
                ((unsigned int *)__bp)[0] = (__this << 1) | __carry;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4186
                __carry = __newCarry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4187
                __bp += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4188
                __nBytes -= 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4189
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4190
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4191
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  4192
#endif
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4193
        while (__nBytes) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4194
            __this = __bp[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4195
            __newCarry = (__this >> 7) /* & 1 */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4196
            __bp[0] = (__this << 1) | __carry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4197
            __carry = __newCarry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4198
            __bp++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4199
            __nBytes--;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4200
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4201
        RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4202
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4203
%}.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4204
    self primitiveFailed
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4205
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4206
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4207
     100000 asLargeInteger mul2 
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4208
     10000000000000000000000000000 mul2 
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4209
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4210
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4211
    "Modified: 5.11.1996 / 16:37:32 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4212
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4213
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4214
mul256
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4215
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4216
       destructively multiply the receiver by 256."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4217
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4218
    |newDigits newSize|
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4219
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4220
    newSize := digitByteArray size + 1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4221
    newDigits := ByteArray uninitializedNew:newSize.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4222
"/    newDigits replaceFrom:2 with:digitByteArray startingAt:1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4223
    newDigits replaceBytesFrom:2 to:newSize with:digitByteArray startingAt:1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4224
    newDigits at:1 put:0.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4225
    digitByteArray := newDigits
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4226
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4227
    "Modified: / 20.5.1999 / 09:16:42 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4228
!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4229
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4230
numberOfDigits:nDigits
2001
8c2b957f0cb3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
  4231
"/    digitByteArray := ByteArray uninitializedNew:nDigits.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4232
    digitByteArray := ByteArray new:nDigits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4233
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4234
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4235
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4236
setDigits:digits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4237
    digitByteArray := digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4238
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4239
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4240
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4241
sign:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4242
    sign := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4243
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4244
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4245
!LargeInteger methodsFor:'testing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4246
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4247
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4248
    "return true if the receiver is even"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4249
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4250
    ^ (digitByteArray at:1) even
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4251
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4252
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4253
negative
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4254
    "return true, if the receiver is < 0"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4255
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4256
    ^ (sign < 0)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4257
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4258
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4259
odd
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4260
    "return true if the receiver is odd"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4261
1983
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  4262
    ^ (digitByteArray at:1) odd
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  4263
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  4264
    "Modified: 18.11.1996 / 22:19:19 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4265
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4266
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4267
positive
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4268
    "return true, if the receiver is >= 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4269
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4270
    ^ (sign >= 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4271
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4272
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4273
sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4274
    "return the sign of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4275
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4276
    ^ sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4277
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4278
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4279
strictlyPositive
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4280
    "return true, if the receiver is > 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4281
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4282
    ^ (sign > 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4283
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4284
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  4285
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4286
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4287
version
5002
e895e251d501 __longIntVal has been renamed to __unsignedLongIntVal
Stefan Vogel <sv@exept.de>
parents: 5000
diff changeset
  4288
    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.148 1999-11-18 16:10:32 stefan Exp $'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4289
! !