LargeInteger.st
author Claus Gittinger <cg@exept.de>
Fri, 04 Jun 1999 10:36:28 +0200
changeset 4260 7c70ef5ea136
parent 4256 04905f1fa63f
child 4261 2e2697a523f9
permissions -rw-r--r--
checkin from browser
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
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    44
    (more key-methods should be rewritten as primitives),
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    45
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    46
    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
    47
    SmallInteger arithmetic (overflowing the SmallInteger range).
357
claus
parents: 345
diff changeset
    48
    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
    49
    SmallIntegers, when possible (see #compressed).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    50
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    51
    In contrast to ST-80, there is only one class for LargeIntegers, keeping
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    52
    the sign as an instance variable (ST-80 has LargePositiveInteger and
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    53
    LargeNegativeInteger). This may change.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    54
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    55
    [author:]
4211
1727ceb45fbe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4194
diff changeset
    56
	Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    57
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    58
    [see also:]
4211
1727ceb45fbe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4194
diff changeset
    59
	Number
1727ceb45fbe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4194
diff changeset
    60
	Float Fraction FixedPoint 
1727ceb45fbe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4194
diff changeset
    61
	SmallInteger
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    62
"
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    63
!
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
testing
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    66
"
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    67
   test largeInt multiplication & division 
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    68
   (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
    69
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    70
   |last v|
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    71
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    72
   v := last := 1.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    73
   2 to:3000 do:[:i |
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    74
       i printCR.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    75
       v := v * i.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    76
       (v / i) ~= last ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
    77
	   self halt
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    78
       ].
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    79
       last := v.
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    80
   ]
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    81
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
   test addition, subtraction:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    84
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    85
   SmallInteger maxVal                -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    86
   SmallInteger maxVal + 1            -> 1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    87
   SmallInteger maxVal + 2            -> 1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    88
   (SmallInteger maxVal + 2) - 2      -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    89
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    90
   SmallInteger minVal                -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    91
   SmallInteger minVal - 1            -> -1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    92
   SmallInteger minVal - 2            -> -1073741826
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    93
   (SmallInteger minVal - 2) + 2      -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    94
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    95
   1234567890 + 10                    -> 1234567900
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    96
   1111111111 + 1111111111            -> 2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    97
   1111111111 - 1111111111            -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    98
   1111111111 - 2222222222            -> -1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    99
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   100
   1111111111 * 2                     -> 2222222222
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
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   103
   1111111111 * 1111111111            -> 1234567900987654321
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   104
   1234567900987654321 // 1111111111  -> 1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   105
   1234567900987654321 \\ 1111111111  -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   106
   1234567900987654322 \\ 1111111111  -> 1
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   107
   1234567900987654421 \\ 1111111111  -> 100
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   108
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   109
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   110
   addition:
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   111
   (16rFFFFFFF0 + 1          ) hexPrintString -> 'FFFFFFF1'     
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   112
   (16rFFFFFFFF + 1          ) hexPrintString -> '100000000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   113
   (16rFFFFFFFF + 2          ) hexPrintString -> '100000001'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   114
   (16rFFFFFFFF + 16rFFFFFF  ) hexPrintString -> '100FFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   115
   (16rFFFFFFFF + 16rFFFFFFFF) hexPrintString -> '1FFFFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   116
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   117
   20 factorial         -> 2432902008176640000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   118
   20 factorial + 10000 -> 2432902008176650000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   119
   20 factorial               hexPrintString -> '21C3677C82B40000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   120
   (20 factorial + 16rFFFF)   hexPrintString -> '21C3677C82B4FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   121
   (20 factorial + 16rFFFFFF) hexPrintString -> '21C3677C83B3FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   122
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   123
   test comparison:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   124
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   125
   -1234567890 >  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   126
   -1234567890 >= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   127
   -1234567890 <  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   128
   -1234567890 <= -1234567890         true
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         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   131
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   132
   -1234567890 >  -1234567891         true
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         false
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         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   138
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   139
   -1234567891 >  -1234567890         false
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         true
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         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   144
   -1234567891 ~= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   145
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   146
    1234567890 >  -1234567890         true
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         false
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         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   152
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   153
   -1234567890 >  1234567890          false
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          true
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          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   158
   -1234567890 ~= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   159
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   160
    1234567890 >  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   161
    1234567890 >= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   162
    1234567890 <  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   163
    1234567890 <= 1234567890          true
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          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   166
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   167
   -1234567890 >  -10                 false
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                 true
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                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   172
   -1234567890 ~= -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   173
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   174
   -1234567890 >  10                  false
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                  true
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                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   179
   -1234567890 ~= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   180
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   181
   -10 >  -1234567890                 true
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                 false
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                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   187
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   188
    10 >  -1234567890                 true
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                 false
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                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   194
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   195
    1234567890 >  -10                 true  
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                 false  
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                 true  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   201
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   202
    1234567890 >  10                  true
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                  false
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                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   208
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   209
   -10 >   1234567890                 false
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                 true
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                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   214
   -10 ~=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   215
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   216
    10 >   1234567890                 false
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                 true
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                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   221
    10 ~=  1234567890                 true
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
   222
"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   223
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   224
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   225
!LargeInteger class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   226
a27a279701f8 Initial revision
claus
parents:
diff changeset
   227
new
a27a279701f8 Initial revision
claus
parents:
diff changeset
   228
    "catch creation message"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   229
a27a279701f8 Initial revision
claus
parents:
diff changeset
   230
    self error:'LargeIntegers cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
   231
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   232
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   233
new:numberOfDigits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   234
    "catch creation message"
2
claus
parents: 1
diff changeset
   235
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   236
    self error:'LargeIntegers cannot be created with new'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   237
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   238
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   239
value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   240
    "create and return a new LargeInteger with value taken from
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   241
     the argument, aSmallInteger.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   242
     Notice: 
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   243
	this should be only used internally, since such small
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   244
	largeIntegers do not normally occur in the system.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   245
	(They are used by myself)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   246
     May change/be removed without notice."
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   247
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   248
    ^ self basicNew value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   249
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   250
    "LargeInteger value:3689"
3438
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   251
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   252
    "Modified: / 8.5.1998 / 21:40:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   253
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   254
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   255
!LargeInteger class methodsFor:'queries'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   256
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   257
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   258
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   259
     Here, true is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   260
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   261
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   262
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   263
    "Modified: 23.4.1996 / 15:59:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   265
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   266
!LargeInteger methodsFor:'arithmetic'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   267
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   268
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   269
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   270
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   271
    |otherSign numberClass|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   272
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   273
    (sign == 0) ifTrue:[^ 0].  "cannot happen if correctly normalized"
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
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   276
     this is the common case, multiplying with SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   277
     Use a special method for this case ...
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   278
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   279
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   280
	^ self productFromInteger:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   281
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   282
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   283
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   284
     if the argument is not a largeInteger, coerce
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   285
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   286
    (numberClass == self class) ifFalse:[
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
	^ self retry:#* coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   288
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   289
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   290
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   291
    (sign == otherSign) ifTrue:[^ self absMul:aNumber].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   292
    (otherSign == 0) ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   293
    ^ (self absMul:aNumber) sign:-1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   294
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   295
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   296
+ aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   297
    "return the sum of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   298
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   299
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   300
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   301
    (sign == 0) ifTrue:[^ aNumber].  "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   302
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   303
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   304
     this is the common case, adding a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   305
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   306
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   307
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   308
	^ self sumFromInteger:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   309
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   310
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   311
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   312
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   313
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   314
    (numberClass == self class) ifFalse:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   315
	^ self retry:#+ coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   316
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   317
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   318
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   319
    (sign > 0) ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   320
	"I am positive"
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   321
	(otherSign > 0) ifTrue:[^ self absPlus:aNumber sign:1].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   322
	(otherSign < 0) ifTrue:[^ self absMinus:aNumber sign:1].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   323
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   324
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   325
    "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
   326
    (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
   327
    (otherSign < 0) ifTrue:[^ self absPlus:aNumber sign:-1].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   328
    ^ self
357
claus
parents: 345
diff changeset
   329
claus
parents: 345
diff changeset
   330
    "
claus
parents: 345
diff changeset
   331
     SmallInteger maxVal 
claus
parents: 345
diff changeset
   332
     SmallInteger maxVal + 1  
claus
parents: 345
diff changeset
   333
     SmallInteger maxVal + 2 
claus
parents: 345
diff changeset
   334
     SmallInteger minVal    
claus
parents: 345
diff changeset
   335
     SmallInteger minVal - 1
claus
parents: 345
diff changeset
   336
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   337
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   338
    "Modified: / 9.1.1998 / 13:26:28 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   339
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   340
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   341
- aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   342
    "return the difference of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   343
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   344
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   345
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   346
    (sign == 0) ifTrue:[^ aNumber negated].     "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   347
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   348
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   349
     this is the common case, subtracting a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   350
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   351
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   352
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   353
        sign > 0 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   354
            aNumber > 0 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   355
                ^ self absFastMinus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   356
            ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   357
            ^ self absFastPlus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   358
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   359
        aNumber > 0 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   360
            ^ self absFastPlus:aNumber sign:-1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   361
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   362
        ^ self absFastMinus:aNumber sign:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   363
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   364
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   365
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   366
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   367
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   368
    (numberClass == self class) ifFalse:[
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   369
        ^ self retry:#- coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   370
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   371
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   372
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   373
    (sign > 0) ifTrue:[
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   374
        "I am positive"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   375
        (otherSign > 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   376
            "+large - +large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   377
            ^ self absMinus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   378
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   379
        (otherSign < 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   380
            "+large - -large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   381
            ^ self absPlus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   382
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   383
        "should not happen"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   384
        ^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   385
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   386
    "I am negative"
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   387
    (otherSign > 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   388
        "-large - +large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   389
        ^ self absPlus:aNumber sign:-1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   390
    ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   391
    (otherSign < 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   392
        "-large - -large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   393
        ^ self absMinus:aNumber sign:-1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   394
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   395
    ^ self
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   396
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   397
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   398
     12345678901234567890 - 0     
357
claus
parents: 345
diff changeset
   399
     12345678901234567890 - 1      
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   400
     12345678901234567890 - -1    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   401
     -12345678901234567890 - 1     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   402
     -12345678901234567890 - -1    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   403
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   404
     12345678901234567890 - 12345678901234567880     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   405
     12345678901234567890 - 12345000000000000000     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   406
     12345678901234567890 - -87654321098765432110    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   407
     -12345678901234567890 - 87654321098765432110    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   408
     -12345678901234567890 - -12345678901234567880   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   409
     -12345678901234567890 - -12345678901234567980   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   410
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   411
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   412
    "Modified: 20.10.1996 / 18:42:16 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   413
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   414
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   415
/ aNumber
1065
77b25fb9f9d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   416
    "return the quotient of the receiver and the argument, aNumber"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   417
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   418
    aNumber isInteger ifTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   419
	^ Fraction numerator:self
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   420
		  denominator:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   421
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   422
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   423
    "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
   424
    ^ (self asFloat / aNumber asFloat)
2793
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   425
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   426
    "Modified: 28.7.1997 / 19:07:55 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   427
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   428
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   429
// aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   430
    "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
   431
     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
   432
     if the operands signs differ."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   433
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   434
    |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
   435
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   436
    cls := aNumber class.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   437
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   438
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   439
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   440
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   441
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   442
    (cls == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   443
	abs := aNumber.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   444
	abs := abs abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   445
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   446
	    divMod := self absFastDivMod:abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   447
	] ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   448
	    n := abs asLargeInteger.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   449
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   450
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   451
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   452
	 if the argument is not a largeInteger, coerce
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   453
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   454
	(cls == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   455
	    ^ self retry:#// coercing:aNumber
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   456
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   457
	n := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   458
    ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   459
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   460
    divMod isNil ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   461
	divMod := self absDivMod:n.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   462
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   463
    quo := divMod at:1.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   464
    (sign == aNumber sign) ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   465
	"/ adjust for truncation if negative and there is a remainder ...
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   466
	quo := quo sign:-1.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   467
	(divMod at:2) == 0 ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   468
	    ^ quo - 1
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   469
	].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   470
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   471
    ^ quo
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   472
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   473
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   474
     (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
   475
     (-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
   476
     (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
   477
     (-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
   478
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   479
     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
   480
     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
   481
     16rfffffffff // 16r001fffff  =  32768 ifFalse:[self halt].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   482
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   483
     900 quo: 400   
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   484
     -900 quo: 400                   
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   485
     900 quo: -400                   
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   486
     -900 quo: -400 
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   487
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   488
     9000000000 quo: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   489
     -9000000000 quo: 4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   490
     9000000000 quo: -4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   491
     -9000000000 quo: -4000000000 
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   492
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   493
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   494
    "Modified: / 5.11.1996 / 16:39:36 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   495
    "Modified: / 27.4.1999 / 19:50:26 / stefan"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   496
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   497
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   498
\\ aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   499
    "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
   500
     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
   501
     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
   502
     Compare with #rem:"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   503
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   504
    |abs rem negativeDivisor|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   505
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   506
    aNumber negative ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   507
	negativeDivisor := true.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   508
	abs := aNumber negated.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   509
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   510
	negativeDivisor := false.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   511
	abs := aNumber.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   512
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   513
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   514
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   515
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   516
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   517
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   518
    (aNumber class == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   519
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   520
	    rem := (self absFastDivMod:abs) at:2.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   521
	] ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   522
	    rem := self absMod:abs asLargeInteger
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   523
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   524
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   525
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   526
	 if the argument is not a largeInteger, coerce
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   527
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   528
	(aNumber class == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   529
	    ^ self retry:#\\ coercing:aNumber
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   530
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   531
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   532
	rem := self absMod:abs.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   533
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   534
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   535
    rem = 0 ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   536
	negativeDivisor ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   537
	    rem := rem sign:-1
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   538
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   539
	(self negative ~~ negativeDivisor) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   540
	    "different sign, so remainder would have been negative.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   541
	     rem has been rounded toward zero, this code will simulate
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   542
	     rounding to negative infinity."
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
	    rem := aNumber - rem.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   545
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   546
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   547
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   548
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   549
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   550
     (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
   551
     (-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
   552
     (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
   553
     (-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
   554
     (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
   555
     (-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
   556
     (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
   557
     (-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
   558
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   559
     9000000000 \\ 7      
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   560
     -9000000000 \\ 7     
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   561
     9000000000 \\ -7     
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   562
     -9000000000 \\ -7    
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   563
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   564
     900 rem: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   565
     -900 rem: 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   566
     900 rem: -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   567
     -900 rem: -400               
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   568
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   569
     9000000000 rem: 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   570
     -9000000000 rem: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   571
     9000000000 rem: -4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   572
     -9000000000 rem: -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   573
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   574
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   575
    "Modified: / 5.11.1996 / 17:10:10 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   576
    "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
   577
!
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   578
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   579
divMod:aNumber
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   580
    "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
   581
     self \\ aNumber.
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   582
     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
   583
     argument."
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   584
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   585
    |cls n|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   586
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   587
    cls := aNumber class.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   588
    (cls == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   589
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   590
	 this is the common case, dividing by a SmallInteger.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   591
	 Use a special method for this case ...
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   592
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   593
	(aNumber between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   594
	    ^ self absFastDivMod:aNumber abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   595
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   596
	n := aNumber asLargeInteger.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   597
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   598
	(cls == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   599
	    ^ super divMod:aNumber            
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   600
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   601
	n := aNumber.
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   602
    ].
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   603
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   604
    ^ self absDivMod:n abs
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   605
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   606
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   607
     9000000000 // 4000000000   => 2
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   608
     9000000000 \\ 4000000000   => 1000000000 
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   609
     9000000000 divMod: 4000000000   => #(2 1000000000)
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   610
    "
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
    "Created: / 29.10.1996 / 21:22:05 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   613
    "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
   614
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   615
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   616
negated
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   617
    "return an integer with value negated from the receivers value."
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   618
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   619
    |newNumber sz|
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   620
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   621
    (sign == 0) ifTrue:[^ 0].
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   622
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   623
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   624
     special case for SmallInteger minVal
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   625
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   626
    sign == 1 ifTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   627
	sz := digitByteArray size.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   628
%{
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   629
	int idx;
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   630
	unsigned char *bp;
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   631
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   632
	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
   633
	idx = __intVal(sz);
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   634
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   635
	while ((idx > 1) && (bp[idx-1] == 0)) idx--;
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   636
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   637
	if (idx == sizeof(INT)) {
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   638
#if defined(alpha64)
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   639
	    if ( ((unsigned INT *)bp)[0] == 0x4000000000000000L)
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   640
#else
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   641
# if defined(i386) /* actually: LSBFIRST */
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   642
	    if ( ((unsigned INT *)bp)[0] == 0x40000000)
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   643
# else
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   644
	    /*
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   645
	     * generic code
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   646
	     */
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   647
	    if ((bp[idx-1] == 0x40)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   648
	     && (bp[idx-2] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   649
	     && (bp[idx-3] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   650
	     && (bp[idx-4] == 0)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   651
#  ifdef alpha64
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   652
	     && (bp[idx-5] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   653
	     && (bp[idx-6] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   654
	     && (bp[idx-7] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   655
	     && (bp[idx-8] == 0)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   656
#  endif
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   657
	    ) 
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   658
# endif
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   659
#endif
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   660
	    {
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   661
		RETURN (__MKSMALLINT(_MIN_INT));
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   662
	    }
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   663
	}
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   664
%}.
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   665
"/      sz == 4 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   666
"/        (digitByteArray at:1) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   667
"/          (digitByteArray at:2) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   668
"/            (digitByteArray at:3) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   669
"/              (digitByteArray at:4) == 16r40 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   670
"/                ^ SmallInteger minVal
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   671
"/              ].
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   672
"/            ]
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   673
"/          ]
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   674
"/        ]
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   675
"/      ]
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   676
    ].
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   677
    newNumber := self shallowCopy.
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   678
    newNumber sign:(sign negated).
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   679
    ^ newNumber
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   680
!
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   681
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   682
quo:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   683
    "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
   684
     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
   685
     truncates toward negative infinity).
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   686
     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
   687
     different from the args sign"
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   688
2521
43b9d4fafb35 removed unused locals
Claus Gittinger <cg@exept.de>
parents: 2495
diff changeset
   689
    |otherSign quo abs "{ Class: SmallInteger }" |
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   690
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   691
    otherSign := aNumber sign.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   692
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   693
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   694
     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
   695
     Use a special method for this case ...
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   696
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   697
    (aNumber class == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   698
	abs := aNumber.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   699
	abs := abs abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   700
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   701
	    quo := (self absFastDivMod:abs) at:1.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   702
	    (sign == otherSign) ifTrue:[^ quo].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   703
	    ^ quo sign:-1
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   704
	]
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   705
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   706
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   707
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   708
     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
   709
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   710
    (aNumber class == self class) ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   711
	^ self retry:#quo: coercing:aNumber
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   712
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   713
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   714
    sign < 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   715
	(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
   716
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   717
	(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
   718
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   719
    ^ ((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
   720
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   721
    "
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   722
     900 // 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   723
     -900 // 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   724
     900 // -400 
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   725
     -900 // -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   726
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   727
     9000000000 // 4000000000     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   728
     -9000000000 // 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   729
     9000000000 // -4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   730
     -9000000000 // -4000000000   
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   731
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   732
     900 quo: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   733
     -900 quo: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   734
     900 quo: -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   735
     -900 quo: -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   736
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   737
     9000000000 quo: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   738
     -9000000000 quo: 4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   739
     9000000000 quo: -4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   740
     -9000000000 quo: -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   741
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   742
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   743
    "Modified: / 5.11.1996 / 14:14:17 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   744
    "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
   745
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   746
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   747
rem:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   748
    "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
   749
     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
   750
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   751
    |rem abs "{ Class: SmallInteger }" |
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   752
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   753
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   754
     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
   755
     Use special code for this case ...
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   756
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   757
    (aNumber class == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   758
	abs := aNumber.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   759
	abs := abs abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   760
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   761
	    rem := (self absFastDivMod:abs) at:2.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   762
	] ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   763
	    rem := self absMod:abs asLargeInteger
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   764
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   765
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   766
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   767
	 if the argument is not a largeInteger, coerce
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   768
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   769
	(aNumber class == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   770
	    ^ self retry:#rem coercing:aNumber
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   771
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   772
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   773
	rem := self absMod:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   774
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   775
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   776
    sign < 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   777
	^ rem sign:-1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   778
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   779
    ^ rem
927
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
    "
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   782
     900 \\ 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   783
     -900 \\ 400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   784
     900 \\ -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   785
     -900 \\ -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   786
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   787
     9000000000 \\ 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   788
     -9000000000 \\ 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   789
     9000000000 \\ -4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   790
     -9000000000 \\ -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   791
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   792
     900 rem: 400     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   793
     -900 rem: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   794
     900 rem: -400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   795
     -900 rem: -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   796
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   797
     9000000000 rem: 4000000000     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   798
     -9000000000 rem: 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   799
     9000000000 rem: -4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   800
     -9000000000 rem: -4000000000   
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   801
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   802
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   803
    "Modified: / 5.11.1996 / 14:02:59 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   804
    "Modified: / 29.4.1999 / 11:26:51 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   805
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   806
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   807
!LargeInteger methodsFor:'bit operators'!
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   808
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   809
lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   810
    "return the bitIndex of the lowest bit set. The returned bitIndex
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   811
     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
   812
     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
   813
     Redefined here for more performance of the gcd: algorithm, which
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   814
     is used when big fractions are reduced."
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   815
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   816
    |sz "{ Class: SmallInteger }"
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   817
     byte|
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   818
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   819
    sz := digitByteArray size.
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   820
    1 to:sz do:[:digitIndex |
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   821
	(byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   822
	    ^ (digitIndex-1)*8 + byte lowBit
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   823
	]
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   824
    ].
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   825
    ^ -1
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   826
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   827
    "
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   828
     (1 bitShift:30) lowBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   829
     (1 bitShift:30) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   830
     (1 bitShift:31) lowBit   
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   831
     (1 bitShift:31) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   832
     (1 bitShift:32) lowBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   833
     (1 bitShift:32) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   834
     (1 bitShift:33) lowBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   835
     (1 bitShift:33) highBit 
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   836
     (1 bitShift:64) lowBit 
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   837
     (1 bitShift:64) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   838
     (1 bitShift:1000) lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   839
     (1 bitShift:1000) highBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   840
     ((1 bitShift:64)-1) lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   841
     ((1 bitShift:64)-1) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   842
    "
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   843
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   844
    "Modified: 14.8.1997 / 11:55:34 / cg"
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   845
! !
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   846
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   847
!LargeInteger methodsFor:'byte access'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   848
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   849
digitAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   850
    "return 8 bits of value, starting at byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   851
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   852
    index > digitByteArray size ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   853
    ^ digitByteArray at:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   854
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   855
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   856
digitAt:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   857
    "set the 8 bits, index is a byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   858
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   859
    digitByteArray at:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   860
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   861
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   862
digitByteAt:index
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   863
    "return 8 bits of my signed value, starting at byte index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   864
     For positive receivers, this is the same as #digitAt:;
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   865
     for negative ones, the actual bit representation is returned."
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   866
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   867
    |t digits|
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   868
    sign < 0 ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   869
	index > digitByteArray size ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   870
	    ^ 0
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   871
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   872
	^ digitByteArray at:index.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   873
    ].
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   874
    "/ negative int - do 2's complement here
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   875
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   876
    t := self bitInvert + 1.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   877
    t sign:1.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   878
    digits := t digits.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   879
    index > digits size ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   880
	^ 16rFF
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   881
    ].
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   882
    ^ digits at:index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   883
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   884
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   885
     16r11111111111111111111 negated digitByteAt:1
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   886
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   887
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   888
    "Created: / 25.10.1998 / 14:12:21 / cg"
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   889
!
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   890
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   891
digitLength
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   892
    "return the number bytes used by this Integer.
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   893
     For negative receivers, the digitLength of its absolute value
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   894
     is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   895
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   896
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   897
     check if there is a 0-byte ...
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   898
     this allows to ask unnormalized LargeIntegers 
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   899
     for their digitLength
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   900
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   901
    |l "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   902
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   903
    l := digitByteArray size.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   904
    [l ~~ 0 and:[(digitByteArray at:l) == 0]] whileTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   905
	l := l - 1.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   906
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   907
    ^ l
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   908
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   909
    "Modified: 31.7.1997 / 13:18:28 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   910
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   911
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   912
digits
4151
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
   913
    "return a byteArray filled with the receivers bits
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   914
     (8 bits of the absolute value per element)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   915
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   916
    ^ digitByteArray
4151
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
   917
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
   918
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   919
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   920
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   921
!LargeInteger methodsFor:'coercing & converting'!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   922
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   923
asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   924
    "return a Float with same value as myself.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   925
     Since floats have a limited precision, you usually loose bits when
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   926
     doing this."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   927
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   928
    |newFloat|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   929
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   930
    newFloat := 0.0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   931
    (sign == 0) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   932
	digitByteArray reverseDo:[:aDigit |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   933
	    newFloat := (newFloat * 256.0) + aDigit asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   934
	].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   935
	(sign < 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   936
	    newFloat := newFloat negated
345
claus
parents: 250
diff changeset
   937
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   938
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   939
    ^ newFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   940
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   941
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   942
     1234567890 asFloat               
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   943
     12345678901234567890 asFloat      
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   944
     12345678901234567890 asFloat asInteger   
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   945
    "
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   948
asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   949
    "return a LargeInteger with same value as myself - thats me"
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
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   952
!
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
asSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   955
    "return a SmallInteger with same value as myself - 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   956
     the result is invalid if the receivers value cannot 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   957
     be represented as a SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   958
     Q: should we raise an exception if this happens ?"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   959
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   960
    |value|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   961
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   962
    value := 0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   963
    (sign == 0) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   964
	digitByteArray reverseDo:[:aDigit |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   965
	    value := (value times:256) + aDigit 
345
claus
parents: 250
diff changeset
   966
	].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   967
	(sign < 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   968
	    value := value negated
345
claus
parents: 250
diff changeset
   969
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   970
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   971
    ^ value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   972
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   973
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   974
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   975
    "return the argument as a LargeInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   976
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   977
    ^ aNumber asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   978
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   979
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   980
compressed
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   981
    "if the receiver can be represented as a SmallInteger, return
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
   982
     a SmallInteger with my value; 
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
   983
     otherwise remove leading zero bytes in the digitByte array
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
   984
     and return the receiver"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   985
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   986
    |index "{ Class: SmallInteger }" 
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
   987
     val   "{ Class: SmallInteger }" 
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
   988
     index0
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
   989
    |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   990
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   991
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   992
    OBJ t;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   993
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   994
    if (__INST(sign) == __MKSMALLINT(0)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
   995
        RETURN (__MKSMALLINT(0));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   996
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   997
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   998
    t = __INST(digitByteArray);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   999
    if (__isByteArray(t)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1000
        unsigned char *_digitBytes = __ByteArrayInstPtr(t)->ba_element;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1001
        int _idx, _idx0;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1002
        INT _val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1003
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1004
        _idx = _idx0 = __byteArraySize(t);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1005
        while ((_idx > 0) && (_digitBytes[_idx - 1] == 0)) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1006
            _idx--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1007
        }
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
  1008
#ifdef alpha64
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1009
        switch (_idx) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1010
            case 8:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1011
                _val = _digitBytes[7];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1012
                if (_val <= 0x40) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1013
                    _val = (_val<<8);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1014
                    _val = (_val + _digitBytes[6]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1015
                    _val = (_val + _digitBytes[5]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1016
                    _val = (_val + _digitBytes[4]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1017
                    _val = (_val + _digitBytes[3]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1018
                    _val = (_val + _digitBytes[2]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1019
                    _val = (_val + _digitBytes[1]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1020
                    _val += _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1021
                    if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1022
                        _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1023
                    if ((_val >= _MIN_INT) && (_val <= _MAX_INT)) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1024
                        RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1025
                    }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1026
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1027
                break;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1028
            case 7:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1029
                _val = (_digitBytes[6]<<8);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1030
                _val = (_val + _digitBytes[5]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1031
                _val = (_val + _digitBytes[4]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1032
                _val = (_val + _digitBytes[3]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1033
                _val = (_val + _digitBytes[2]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1034
                _val = (_val + _digitBytes[1]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1035
                _val += _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1036
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1037
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1038
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1039
            case 6:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1040
                _val = (_digitBytes[5]<<8);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1041
                _val = (_val + _digitBytes[4]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1042
                _val = (_val + _digitBytes[3]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1043
                _val = (_val + _digitBytes[2]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1044
                _val = (_val + _digitBytes[1]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1045
                _val += _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1046
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1047
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1048
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1049
            case 5:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1050
                _val = (_digitBytes[4]<<8);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1051
                _val = (_val + _digitBytes[3]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1052
                _val = (_val + _digitBytes[2]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1053
                _val = (_val + _digitBytes[1]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1054
                _val += _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1055
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1056
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1057
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1058
            case 4:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1059
                _val = (_digitBytes[3]<<8);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1060
                _val = (_val + _digitBytes[2]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1061
                _val = (_val + _digitBytes[1]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1062
                _val += _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1063
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1064
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1065
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1066
            case 3:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1067
                _val = (_digitBytes[2]<<8);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1068
                _val = (_val + _digitBytes[1]) << 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1069
                _val += _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1070
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1071
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1072
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1073
            case 2:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1074
                _val = (_digitBytes[1]<<8) + _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1075
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1076
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1077
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1078
            case 1:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1079
                _val = _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1080
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1081
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1082
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1083
            case 0:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1084
                RETURN (__MKSMALLINT(0));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1085
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1086
        }
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1087
#else
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1088
        if (_idx <= 4) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1089
            if (_idx <= 2) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1090
                if (_idx == 0) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1091
                    RETURN (__MKSMALLINT(0));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1092
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1093
                if (_idx == 1) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1094
                    _val = _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1095
                    if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1096
                        _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1097
                    RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1098
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1099
                _val = (_digitBytes[1]<<8) + _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1100
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1101
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1102
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1103
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1104
            if (_idx == 3) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1105
                _val = (((_digitBytes[2]<<8) + _digitBytes[1])<<8) + _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1106
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1107
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1108
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1109
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1110
            _val = _digitBytes[3];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1111
            if (_val <= 0x40) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1112
                _val = (((((_val<<8) + _digitBytes[2])<<8) + _digitBytes[1])<<8) + _digitBytes[0];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1113
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1114
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1115
                if ((_val >= _MIN_INT) && (_val <= _MAX_INT)) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1116
                    RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1117
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1118
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1119
        }
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1120
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1121
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1122
        if (_idx == _idx0) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1123
            RETURN (self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1124
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1125
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1126
        /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1127
         * must copy & cut off some bytes
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1128
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1129
        {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1130
            OBJ newDigits;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1131
            OBJ oldDigits;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1132
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1133
            /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1134
             * careful - there is no context here to protect
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1135
             * the receiver ...
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1136
             */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1137
            __PROTECT__(self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1138
            __PROTECT__(__INST(digitByteArray));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1139
            newDigits = __BYTEARRAY_UNINITIALIZED_NEW_INT(_idx);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1140
            __UNPROTECT__(oldDigits);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1141
            __UNPROTECT__(self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1142
            if (newDigits) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1143
                bcopy(__ByteArrayInstPtr(oldDigits)->ba_element,
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1144
                      __ByteArrayInstPtr(newDigits)->ba_element,
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1145
                      _idx);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1146
                __INST(digitByteArray) = newDigits; __STORE(self, newDigits);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1147
                RETURN (self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1148
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1149
            /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1150
             * allocation failed ...
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1151
             * ... fall through to trigger the error
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1152
             */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1153
        }
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1154
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1155
%}.
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1156
    index0 := index := digitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1157
    [(index > 0) and:[(digitByteArray at:index) == 0]] whileTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1158
        index := index - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1159
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1160
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1161
    (index ~~ index0) ifTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1162
        digitByteArray := digitByteArray copyFrom:1 to:index
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1163
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1164
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1165
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1166
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1167
value:aSmallInteger
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1168
    "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
  1169
     This method will fail, if the argument is not a smallInteger.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1170
     This should only be used internally, 
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1171
     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
  1172
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1173
    |absValue 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1174
     b1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1175
     b2 "{ Class: SmallInteger }"
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1176
     b3 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1177
     b4 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1178
     b5 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1179
     b6 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1180
     b7 "{ Class: SmallInteger }"|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1181
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1182
    "
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1183
     could have simply created a 4-byte largeinteger and normalize it. 
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1184
     The code below does the normalize right away, avoiding the
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1185
     overhead of producing any intermediate byte-arrays (and the scanning)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1186
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1187
    (aSmallInteger == 0) ifTrue: [
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1188
        digitByteArray := ByteArray with:0.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1189
        sign := 0.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1190
        ^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1191
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1192
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1193
    (aSmallInteger < 0) ifTrue: [
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1194
        sign := -1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1195
        absValue := aSmallInteger negated
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1196
    ] ifFalse: [
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1197
        sign := 1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1198
        absValue := aSmallInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1199
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1200
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1201
    b1 := absValue bitAnd:16rFF.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1202
    absValue := absValue bitShift:-8.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1203
    absValue == 0 ifTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1204
        digitByteArray := ByteArray with:b1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1205
    ] ifFalse:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1206
        b2 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1207
        absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1208
        absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1209
            digitByteArray := ByteArray with:b1 with:b2
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1210
        ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1211
            b3 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1212
            absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1213
            absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1214
                digitByteArray := ByteArray with:b1 with:b2 with:b3
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1215
            ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1216
                b4 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1217
                absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1218
                absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1219
                    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1220
                ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1221
                    b5 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1222
                    absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1223
                    absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1224
                        digitByteArray := ByteArray new:5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1225
                        digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1226
                        digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1227
                        digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1228
                        digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1229
                        digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1230
                    ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1231
                        b6 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1232
                        absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1233
                        absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1234
                            digitByteArray := ByteArray new:6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1235
                            digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1236
                            digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1237
                            digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1238
                            digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1239
                            digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1240
                            digitByteArray at:6 put:b6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1241
                        ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1242
                            b7 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1243
                            absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1244
                            absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1245
                                digitByteArray := ByteArray new:7.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1246
                                digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1247
                                digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1248
                                digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1249
                                digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1250
                                digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1251
                                digitByteArray at:6 put:b6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1252
                                digitByteArray at:7 put:b7.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1253
                            ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1254
                                digitByteArray := ByteArray new:8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1255
                                digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1256
                                digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1257
                                digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1258
                                digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1259
                                digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1260
                                digitByteArray at:6 put:b6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1261
                                digitByteArray at:7 put:b7.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1262
                                digitByteArray at:8 put:absValue.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1263
                            ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1264
                        ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1265
                    ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1266
                ]
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
        ]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1269
    ]
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  1270
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1271
    "Modified: / 26.5.1999 / 22:18:14 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1272
! !
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
!LargeInteger methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1275
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1276
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1277
    "return true, if the argument, aNumber is greater than the receiver"
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
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1280
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1281
    (aNumber class == self class) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1282
	^ self retry:#< coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1283
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1284
    otherSign := aNumber sign.
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
    (sign > 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1287
	"I am positive"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1288
	(otherSign > 0) ifTrue:[^ self absLess:aNumber].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1289
	^ false "aNumber is <= 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1290
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1291
    (sign == 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1292
	(otherSign > 0) ifTrue:[^ true].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1293
	^ false
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1294
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1295
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1296
    (otherSign > 0) ifTrue:[^ true].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1297
    (otherSign == 0) ifTrue:[^ true].
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1298
    ^ (aNumber absLess:self)
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1299
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1300
    "Modified: / 14.1.1998 / 12:51:42 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1301
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1302
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1303
= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1304
    "return true, if the argument, aNumber has the same value as
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1305
     the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1306
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1307
    "/ speed up compare to 0
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1308
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1309
    (aNumber == 0 and:[sign == 0]) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1310
	^ true
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1311
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1312
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1313
    (aNumber class == self class) ifFalse:[
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1314
	"/
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1315
	"/ 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
  1316
	"/ 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
  1317
	"/ 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
  1318
	"/
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1319
	aNumber class == SmallInteger ifTrue:[^ false ].
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1320
	aNumber respondsToArithmetic ifFalse:[ ^ false ].
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1321
	^ self retry:#= coercing:aNumber
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1322
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1323
    (aNumber sign == sign) ifFalse:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1324
    ^ self absEq:aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1325
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1326
    "Modified: / 13.2.1998 / 11:43:15 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1327
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1328
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1329
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1330
    "return true, if the argument, aNumber is less than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1331
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1332
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1333
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1334
    (aNumber class == self class) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1335
	^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1336
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1337
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1338
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1339
    (sign > 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1340
	"I am positive"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1341
	(otherSign > 0) ifTrue:[^ aNumber absLess:self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1342
	^ true "aNumber is <= 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1343
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1344
    (sign == 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1345
	"I am zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1346
	(otherSign > 0) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1347
	^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1348
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1349
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1350
    (otherSign > 0) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1351
    (otherSign == 0) ifTrue:[^ false].
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1352
    ^ (self absLess:aNumber)  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1353
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1354
    "Modified: / 14.1.1998 / 12:56:56 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1355
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1356
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1357
!LargeInteger methodsFor:'double dispatching'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1358
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1359
differenceFromInteger:anInteger
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1360
    "sent, when anInteger does not know how to subtract the receiver.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1361
     Return the result of 'anInteger - self'. The argument must be a SmallInteger."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1362
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1363
    anInteger > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1364
	sign > 0 ifTrue:[
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1365
	    ^ self absFastMinus:anInteger sign:-1
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1366
	].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1367
	^ self absFastPlus:anInteger sign:1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1368
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1369
    anInteger == 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1370
	^ self negated
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1371
    ].
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1372
    sign > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1373
	^ self absFastPlus:anInteger negated sign:-1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1374
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1375
    ^ self absFastMinus:anInteger sign:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1376
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1377
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1378
     12345678901234567890          
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1379
     -12345678901234567890         
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1380
     12345678901234567890 differenceFromInteger:0       
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1381
     12345678901234567890 differenceFromInteger:1       
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1382
     12345678901234567890 differenceFromInteger:-1      
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1383
     -12345678901234567890 differenceFromInteger:1   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1384
     -12345678901234567890 differenceFromInteger:-1   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1385
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1386
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1387
    "Modified: 20.10.1996 / 18:41:54 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1388
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1389
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1390
productFromInteger:anInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1391
    "sent, when anInteger does not know how to multiply the receiver.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1392
     Return the product of the receiver and the argument, aSmallInteger"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1393
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1394
    |num result 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1395
     resultDigitByteArray
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1396
     val     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1397
     len     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1398
     carry   "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  1399
     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
  1400
     ok lResult|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1401
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1402
    "multiplying by a small integer is done here"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1403
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1404
    "trivial cases"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1405
    anInteger == 0 ifTrue:[^ 0].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1406
    anInteger == 1 ifTrue:[^ self].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1407
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1408
    num := anInteger abs.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1409
    (num > 16r3FFFFF) ifTrue:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1410
        "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
  1411
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1412
        ^ anInteger retry:#* coercing:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1413
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1414
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1415
    len := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1416
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1417
    val := num.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1418
    val <= 16rFF ifTrue:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1419
        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
  1420
    ] ifFalse:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1421
        val <= 16rFFFF ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1422
            lResult := len + 2
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1423
        ] ifFalse:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1424
            val <= 16rFFFFFF ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1425
                lResult := len + 4.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1426
            ] ifFalse:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1427
                lResult := len + 6.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1428
            ]
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1429
        ]
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1430
    ].
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  1431
    resultDigitByteArray := ByteArray uninitializedNew:lResult.
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2855
diff changeset
  1432
    result := self class basicNew setDigits:resultDigitByteArray.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1433
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1434
    anInteger < 0 ifTrue:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1435
        sign > 0 ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1436
            result sign:-1
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1437
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1438
    ] ifFalse:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1439
        sign < 0 ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1440
            result sign:sign
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1441
        ]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1442
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1443
85
claus
parents: 77
diff changeset
  1444
    ok := false.
claus
parents: 77
diff changeset
  1445
%{
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1446
    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
  1447
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1448
    if (__isSmallInteger(len)
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1449
     && __isByteArray(__digitByteArray)
85
claus
parents: 77
diff changeset
  1450
     && __isByteArray(resultDigitByteArray)) {
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1451
        INT _l = __intVal(len);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1452
        INT _v = __intVal(val);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1453
        unsigned INT _carry = 0;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1454
        unsigned INT _prod;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1455
        unsigned char *digitP = __ByteArrayInstPtr(__digitByteArray)->ba_element;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1456
        unsigned char *resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1457
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1458
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1459
         * skipping zeros does not help much (a few percent) on
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1460
         * a P5 or other CPUS with a fast multiplier. 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1461
         * 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
  1462
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1463
        while ((_l >= sizeof(INT)) && (((unsigned INT *)digitP)[0] == 0)) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1464
             ((unsigned long *)resultP)[0] = 0;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1465
            digitP += sizeof(INT);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1466
            resultP += sizeof(INT);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1467
            _l -= sizeof(INT);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1468
        }
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1469
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1470
#if defined(i386) || defined(alpha) /* XXX actually: LSB_FIRST */
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1471
# if defined (__GNUC__) && defined(i386)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1472
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1473
         * can do it long-word-wise;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1474
         * 32*32 -> 64 multiplication
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1475
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1476
        while (_l > 3) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1477
            unsigned __pHi, __pLow;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1478
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1479
            /* 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1480
             * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1481
             * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1482
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1483
            asm ("mull %3               \n
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1484
                  addl %4,%%eax         \n
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1485
                  adcl $0,%%edx"    
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1486
                    : "=a"  ((unsigned long)(__pLow)),
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1487
                      "=d"  ((unsigned long)(__pHi))
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1488
                    : "0"   ((unsigned long)(((unsigned long *)digitP)[0])),
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1489
                      "1"   ((unsigned long)(_v)),
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1490
                      "rm"  ((unsigned long)(_carry)) );
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1491
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1492
            ((unsigned long *)resultP)[0] = __pLow;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1493
            _carry = __pHi;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1494
            digitP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1495
            resultP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1496
            _l -= 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1497
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1498
# else /* not GNU-i386 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1499
#  if defined (WIN32) && defined(i386)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1500
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1501
         * can do it long-word-wise;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1502
         * 32*32 -> 64 multiplication
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1503
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1504
        while (_l > 3) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1505
            unsigned __pLow;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1506
            unsigned digit; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1507
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1508
            /* 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1509
             * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1510
             * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1511
             */
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1512
/*
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1513
            digit = ((unsigned long *)digitP)[0]; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1514
            edx::eax = (digit * _v);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1515
            edx::eax += _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1516
            ((unsigned long *)resultP)[0] = eax; -- pLow
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1517
            _carry = edx; -- pHigh
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1518
            digitP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1519
            resultP += 4;
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1520
*/
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1521
            digit = ((unsigned long *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1522
            asm {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1523
                mov   eax, digit
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1524
                mov   edx, _v
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1525
                mul   edx
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1526
                add   eax, _carry
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1527
                adc   edx, 0 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1528
                mov   __pLow, eax
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1529
                mov   _carry, edx
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1530
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1531
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1532
            ((unsigned long *)resultP)[0] = __pLow; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1533
            digitP += 4; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1534
            resultP += 4; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1535
            _l -= 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1536
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1537
#  else /* not WIN32-i386 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1538
#   if defined(INT64)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1539
        if (_v <= 0xFFFFFFFFL) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1540
            /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1541
             * have a 64bit int type ... good
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1542
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1543
            UINT64 _prod64;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1544
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1545
            /* have 64bit ints; can do it int-wise
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1546
             *
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1547
             * max: 0xFFFFFFFF * 0xFFFFFFFF -> 0xFFFFFFFE.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1548
             * + maxCarry (0xFFFFFFFF)  -> 0xFFFFFFFF.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1549
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1550
            while (_l > 3) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1551
                unsigned __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1552
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1553
                __t = ((unsigned *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1554
                digitP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1555
                _prod64 = (INT64)_v;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1556
                _prod64 *= __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1557
                _prod64 += _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1558
                ((unsigned *)resultP)[0] = _prod64 /* & 0xFFFFFFFFL */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1559
                _carry = _prod64 >> 32;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1560
                resultP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1561
                _l -= 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1562
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1563
            if (_l > 1) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1564
                unsigned short __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1565
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1566
                __t = ((unsigned short *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1567
                digitP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1568
                _prod64 = (INT64)_v;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1569
                _prod64 *= __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1570
                _prod64 += _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1571
                ((unsigned short *)resultP)[0] = _prod64 /* & 0xFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1572
                _carry = _prod64 >> 16;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1573
                resultP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1574
                _l -= 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1575
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1576
            if (_l > 0) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1577
                _prod64 = *digitP++ * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1578
                *resultP++ = _prod64 /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1579
                _carry = _prod64 >> 8;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1580
                _l--;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1581
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1582
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1583
#   else /* no INT64 type */
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1584
        if (_v <= 0xFFFF) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1585
            /* can do it short-wise 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1586
             * 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1587
             * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1588
             * + maxCarry (0xFFFF)  -> 0xFFFF.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1589
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1590
            while (_l > 1) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1591
                _prod = ((unsigned short *)digitP)[0] * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1592
                ((unsigned short *)resultP)[0] = _prod /* & 0xFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1593
                _carry = _prod >> 16;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1594
                digitP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1595
                resultP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1596
                _l -= 2;
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
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1599
#   endif /* no INT64 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1600
#  endif /* not WIN32-i386 */
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  1601
# endif /* not GNU-i386 */
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  1602
#else /* not LSB_FIRST */
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1603
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1604
# ifdef mips
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1605
#  define LOAD_WORD_WISE
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1606
   /* 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
  1607
# endif
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1608
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1609
        if (_v <= 0xFFFF) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1610
            /* can do it short-wise 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1611
             * 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1612
             * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1613
             * + maxCarry (0xFFFF)  -> 0xFFFF.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1614
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1615
            while (_l > 1) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1616
                unsigned int t;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1617
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1618
#if defined(LOAD_WORD_WISE)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1619
                /* better fetch short-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1620
                t = ((unsigned short *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1621
                digitP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1622
                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
  1623
#else
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1624
                t = (digitP[1]<<8) + digitP[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1625
                digitP += 2;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1626
#endif
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1627
                _prod = t * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1628
                _carry = _prod >> 16;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1629
#if defined(STORE_WORD_WISE)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1630
                /* better store short-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1631
                _prod = ((_prod >> 8) | (_prod << 8)) & 0xFFFF;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1632
                ((unsigned short *)resultP)[0] = _prod;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1633
#else
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1634
                resultP[0] = _prod /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1635
                resultP[1] = (_prod>>8) /* & 0xFF */;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1636
#endif
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1637
                resultP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1638
                _l -= 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1639
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1640
        }
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  1641
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  1642
#endif /* LSB_FIRST */
1797
8dafe47b33fd faster multiplication by an integer.
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
  1643
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1644
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1645
         * rest is done byte-wise
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1646
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1647
        while (_l > 0) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1648
            _prod = *digitP++ * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1649
            *resultP++ = _prod /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1650
            _carry = _prod >> 8;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1651
            _l--;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1652
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1653
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1654
        _l = __intVal(lResult) - __intVal(len);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1655
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1656
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1657
         * remaining carry
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
        while (_carry) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1660
            *resultP++ = _carry /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1661
            _carry >>= 8;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1662
            _l--;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1663
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1664
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1665
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1666
         * remaining zeros
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
        while (_l--) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1669
            *resultP++ = 0;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1670
        }
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
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1673
         * need compress ?
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1674
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1675
        if (resultP[-1]) {
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
             * no
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1678
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1679
            RETURN(result);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1680
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1681
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1682
        ok = true;
85
claus
parents: 77
diff changeset
  1683
    }
claus
parents: 77
diff changeset
  1684
%}.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1685
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1686
     fall back - normally not reached
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1687
     (could make it a primitive-failure as well)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1688
    "
85
claus
parents: 77
diff changeset
  1689
    ok ifFalse:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1690
        carry := 0.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1691
        1 to:len do:[:i |
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1692
            prod := (digitByteArray basicAt:i) * val + carry.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1693
            resultDigitByteArray basicAt:i put:(prod bitAnd:16rFF).
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1694
            carry := prod bitShift:-8.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1695
        ].
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1696
        [carry ~~ 0] whileTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1697
            len := len + 1.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1698
            resultDigitByteArray basicAt:len put:(carry bitAnd:16rFF).
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1699
            carry := carry bitShift:-8
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1700
        ].
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1701
        [len < lResult] whileTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1702
            len := len + 1.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1703
            resultDigitByteArray basicAt:len put:0
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1704
        ]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1705
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1706
    ^ result compressed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1707
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1708
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1709
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1710
    "sent, when anInteger does not know how to add the receiver.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1711
     Return the sum of the receiver and the argument, (which must be a SmallInteger)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1712
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1713
    anInteger > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1714
	sign > 0 ifTrue:[
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1715
	    ^ self absFastPlus:anInteger sign:1
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1716
	].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1717
	^ self absFastMinus:anInteger sign:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1718
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1719
    anInteger == 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1720
	^ self
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1721
    ].
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1722
    sign > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1723
	^ self absFastMinus:anInteger sign:1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1724
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1725
    ^ self absFastPlus:anInteger sign:-1
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1726
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1727
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1728
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1729
     12345678901234567890          
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1730
     -12345678901234567890         
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1731
     12345678901234567890 sumFromInteger:0       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1732
     -12345678901234567890 sumFromInteger:0       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1733
     12345678901234567890 sumFromInteger:1       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1734
     12345678901234567890 sumFromInteger:-1      
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1735
     -12345678901234567890 sumFromInteger:1     
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1736
     -12345678901234567890 sumFromInteger:-1   
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1737
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1738
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1739
    "Modified: / 9.1.1998 / 13:27:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1740
! !
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1741
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1742
!LargeInteger methodsFor:'printing & storing'!
345
claus
parents: 250
diff changeset
  1743
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1744
storeOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1745
    "append a representation of the receiver to aStream, which can
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1746
     be used to reconstruct the receiver."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1747
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1748
    self printOn:aStream.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1749
    aStream nextPutAll:' asLargeInteger'
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1750
! !
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1751
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1752
!LargeInteger methodsFor:'private'!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1753
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1754
absDivMod:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1755
    "return an array with two LargeIntegers representing
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1756
     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
  1757
     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
  1758
     This method needs a rewrite."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1759
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1760
    |dividend divisor 
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1761
     quo digits
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1762
     shift "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1763
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1764
    anInteger == 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1765
	^ DivisionByZeroSignal raise
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1766
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1767
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1768
    self = anInteger ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1769
	^ Array with:1 with:0
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1770
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1771
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1772
    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
  1773
    dividend := self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1774
    shift < 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1775
	^ Array with:0 with:dividend.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1776
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  1777
    shift == 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1778
	divisor := anInteger simpleDeepCopy.
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  1779
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1780
	divisor := anInteger bitShift:shift.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1781
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1782
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1783
    quo := self class basicNew numberOfDigits:((shift // 8) + 1). 
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1784
    digits := quo digits.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1785
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1786
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1787
    [shift > 0] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1788
	(dividend absLess:divisor) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1789
	    digits bitSetAt:shift.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1790
	    (dividend absSubtract: divisor) ifFalse:[ "result == 0"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1791
		^ Array with:quo compressed with:dividend compressed            
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1792
	    ].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1793
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1794
	shift := shift - 1.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1795
	divisor div2.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1796
    ].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1797
    ^ 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
  1798
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1799
    "
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1800
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:4000000000] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1801
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:3000000000] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1802
     16000000000 absDivMod:4000000000 
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1803
     16000000000 absDivMod:3000000000
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1804
    "
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1805
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1806
    "Modified: / 5.11.1996 / 18:40:24 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1807
    "Created: / 27.4.1999 / 19:45:44 / stefan"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1808
    "Modified: / 3.5.1999 / 08:38:01 / stefan"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1809
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1810
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1811
absEq:aLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1812
    "return true, if abs(self) = abs(theArgument)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1813
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1814
    |len1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1815
     len2 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1816
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1817
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1818
     otherDigitByteArray |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1819
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1820
    len1 := digitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1821
    otherDigitByteArray := aLargeInteger digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1822
    len2 := otherDigitByteArray size.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1823
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1824
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1825
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1826
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1827
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1828
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1829
    [(digitByteArray basicAt:len1) == 0] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1830
	len1 := len1 - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1831
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1832
    [(otherDigitByteArray basicAt:len2) == 0] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1833
	len2 := len2 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1834
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1835
    (len1 ~~ len2) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1836
    [len1 > 0] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1837
	d1 := digitByteArray basicAt:len1.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1838
	d2 := otherDigitByteArray basicAt:len1.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1839
	(d1 ~~ d2) ifTrue:[^ false].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1840
	len1 := len1 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1841
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1842
    ^ true
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1843
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1844
    "Modified: / 8.5.1999 / 18:37:02 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1845
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1846
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1847
absFastDivMod:aPositiveSmallInteger
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1848
    "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
  1849
     abs(self) // aPositiveSmallInteger and 
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1850
     abs(self) \\ aPositiveSmallInteger."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1851
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1852
    |tmp1     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1853
     prevRest "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1854
     count    "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  1855
     newDigitByteArray result
claus
parents: 77
diff changeset
  1856
     ok|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1857
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  1858
    aPositiveSmallInteger == 0 ifTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1859
        ^ DivisionByZeroSignal raise
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1860
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1861
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1862
"This cannot happen (if always normalized)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  1863
    self < aPositiveSmallInteger ifTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1864
        ^ Array with:0 with:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1865
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1866
"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1867
    count := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1868
    result := self class basicNew numberOfDigits:count.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1869
    newDigitByteArray := result digits.
85
claus
parents: 77
diff changeset
  1870
    ok := false.
claus
parents: 77
diff changeset
  1871
%{
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  1872
    OBJ __digits;
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  1873
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  1874
    __digits = __INST(digitByteArray);
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  1875
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  1876
    if (__isByteArray(__digits)
85
claus
parents: 77
diff changeset
  1877
     && __isByteArray(newDigitByteArray)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  1878
     && __bothSmallInteger(count, aPositiveSmallInteger)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1879
        unsigned INT rest = 0;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1880
        int index = __intVal(count);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1881
        int index0;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1882
        unsigned INT divisor = __intVal(aPositiveSmallInteger);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1883
        unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1884
        unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1885
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1886
        index0 = index - 1;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1887
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1888
        /* 
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1889
         * divide short-wise 
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1890
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1891
        if (divisor <= 0xFFFF) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1892
            if ((index & 1) == 0) { /* even number of bytes */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1893
                while (index > 1) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1894
                    unsigned INT t;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1895
                    unsigned INT div;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1896
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1897
#if defined(__LSBFIRST) || defined(i386)
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1898
                    index -= 2;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1899
                    t = *((unsigned short *)(&digitBytes[index]));
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  1900
# else
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1901
                    index--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1902
                    t = digitBytes[index];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1903
                    index--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1904
                    t = (t << 8) | digitBytes[index];
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  1905
# endif
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1906
                    t = t | (rest << 16);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1907
                    div = t / divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1908
                    rest = t % divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1909
#if defined(__LSBFIRST) || defined(i386)
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1910
                    *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  1911
# else
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1912
                    resultBytes[index+1] = div >> 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1913
                    resultBytes[index] = div /* & 0xFF */;
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  1914
# endif
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1915
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1916
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1917
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1918
        while (index > 0) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1919
            unsigned INT t;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1920
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1921
            index--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1922
            t = digitBytes[index];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1923
            t = t | (rest << 8);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1924
            resultBytes[index] = t / divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1925
            rest = t % divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1926
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1927
        prevRest = __MKSMALLINT(rest);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1928
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1929
        /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1930
         * no need to normalize ?
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1931
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1932
        while ((index0 >= sizeof(INT)) && (resultBytes[index0]==0)) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1933
            index0--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1934
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1935
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1936
        if (index0 > sizeof(INT)) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1937
            RETURN ( __ARRAY_WITH2(result, prevRest));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1938
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1939
        if ((index0 == sizeof(INT))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1940
         && resultBytes[index0] >= 0x40) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1941
            RETURN ( __ARRAY_WITH2(result, prevRest));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1942
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1943
        /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1944
         * must compress
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1945
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1946
        ok = true;
85
claus
parents: 77
diff changeset
  1947
    }
claus
parents: 77
diff changeset
  1948
%}.
claus
parents: 77
diff changeset
  1949
    "
claus
parents: 77
diff changeset
  1950
     slow code - not normally reached
claus
parents: 77
diff changeset
  1951
     (could also do a primitiveFailure here)
claus
parents: 77
diff changeset
  1952
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1953
    ok ifFalse:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1954
        self primitiveFailed
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1955
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1956
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  1957
    ^ 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
  1958
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1959
    "
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1960
     ((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
  1961
     ((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
  1962
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1963
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1964
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1965
absFastMinus:aSmallInteger sign:newSign
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1966
    "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
  1967
     with sign: newSign.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1968
     The result is normalized.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1969
     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
  1970
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  1971
    |result resultDigitByteArray lastDigit ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  1972
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  1973
     rsltLen "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  1974
     index   "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  1975
     borrow  "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  1976
     diff    "{ Class: SmallInteger }" |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1977
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  1978
    "/ the following code only works with
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  1979
    "/ 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
  1980
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  1981
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  1982
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  1983
        ^ 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
  1984
    ]. 
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  1985
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1986
    len := digitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1987
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  1988
    rsltLen := len "+ 1".
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  1989
    result := self class basicNew numberOfDigits:rsltLen.
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1990
    result sign:newSign.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1991
    resultDigitByteArray := result digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1992
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1993
    borrow := aSmallInteger abs.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1994
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  1995
%{
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  1996
    if (__isByteArray(__INST(digitByteArray))
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  1997
     && __isByteArray(resultDigitByteArray)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1998
        unsigned INT __borrow = __intVal(borrow);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1999
        INT __diff;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2000
        int __index = 1;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2001
        int __len = __intVal(len);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2002
        unsigned char *__digitP = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2003
        unsigned char *__resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2004
        int __len3;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2005
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2006
#if defined(alpha64)
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2007
        /* 
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2008
         * subtract word-wise 
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2009
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2010
        __len3 = __len - 3;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2011
        while (__index < __len3) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2012
            __diff = ((unsigned int *)(__digitP+__index-1))[0] - (__borrow & 0xFFFFFFFFL);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2013
            __borrow >>= 32;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2014
            if (__diff < 0) {
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2015
                /* __diff += 0x100000000; */
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2016
                __borrow++;
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
            ((unsigned int *)(__resultP+__index-1))[0] = __diff;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2019
            __index += 4;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2020
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2021
#endif
4182
a867ecbf5e56 tuned abdFastMinus:
Claus Gittinger <cg@exept.de>
parents: 4181
diff changeset
  2022
#if defined(__LSBFIRST) || defined(i386)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2023
        /* 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2024
         * subtract short-wise 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2025
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2026
        while (__index < __len) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2027
            __diff = ((unsigned short *)(__digitP+__index-1))[0] - (__borrow & 0xFFFF);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2028
            __borrow >>= 16;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2029
            if (__diff < 0) {
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2030
                /* __diff += 0x10000; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2031
                __borrow++;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2032
            } else {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2033
                if (__borrow == 0) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2034
                    ((unsigned short *)(__resultP+__index-1))[0] = __diff;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2035
                    __index += 2;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2036
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2037
                    /* nothing more to subtract .. */
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2038
                    while (__index < __len) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2039
                        ((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
  2040
                        __index += 2;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2041
                    }
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2042
                    if (__index <= __len) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2043
                        __resultP[__index-1] = __digitP[__index-1];
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2044
                    }
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2045
                    break;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2046
                }
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2047
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2048
            ((unsigned short *)(__resultP+__index-1))[0] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2049
            __index += 2;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2050
        }
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2051
#endif
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2052
        while (__index <= __len) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2053
            __diff = __digitP[__index-1] - (__borrow & 0xFF);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2054
            __borrow >>= 8;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2055
            if (__diff < 0) {
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2056
                /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2057
                __borrow++;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2058
            } else {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2059
                if (__borrow == 0) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2060
                    __resultP[__index-1] = __diff;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2061
                    __index++;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2062
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2063
                    /* nothing more to subtract .. */
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2064
                    while (__index <= __len) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2065
                        __resultP[__index-1] = __digitP[__index-1];
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2066
                        __index++;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2067
                    }
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2068
                    break;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2069
                }
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2070
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2071
            __resultP[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2072
            __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2073
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2074
        lastDigit = __MKSMALLINT( __resultP[__index-1-1] );
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2075
        ok = true;
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2076
    }
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2077
%}.
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2078
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2079
    ok == true ifFalse:[        "/ cannot happen
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2080
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2081
        [borrow ~~ 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2082
            (index <= len) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2083
                diff := (digitByteArray basicAt:index) - (borrow bitAnd:16rFF).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2084
                borrow := borrow bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2085
                diff < 0 ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2086
                    diff := diff + 256.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2087
                    borrow := borrow + 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2088
                ]
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2089
            ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2090
                diff := borrow bitAnd:255.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2091
                borrow := borrow bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2092
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2093
            resultDigitByteArray basicAt:index put:(lastDigit := diff).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2094
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2095
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2096
        [index <= len] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2097
            resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2098
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2099
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2100
        (index <= rsltLen) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2101
            lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2102
        ]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2103
    ].
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2104
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2105
    (lastDigit == 0 or:[rsltLen == SmallInteger maxBytes]) ifTrue:[ 
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2106
        ^ result compressed.
4182
a867ecbf5e56 tuned abdFastMinus:
Claus Gittinger <cg@exept.de>
parents: 4181
diff changeset
  2107
    ]. 
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2108
    ^ result
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2109
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2110
    "                                                          
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2111
     12345678900000000000 absFastMinus:1       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2112
     12345678900000000000 absFastMinus:1000000  
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2113
     12345678900000000000 absFastMinus:255
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2114
     (SmallInteger maxVal + 1) absFastMinus:1 sign:1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2115
     (SmallInteger minVal - 1) absFastMinus:1  
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2116
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2117
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2118
    "Modified: 24.3.1997 / 21:33:25 / cg"
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
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2121
absFastPlus:aSmallInteger sign:newSign
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2122
    "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
  2123
     with sign: newSign.
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2124
     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
  2125
     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
  2126
     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
  2127
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2128
    |result resultDigitByteArray lastDigit
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2129
     ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2130
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2131
     rsltLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2132
     index "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2133
     carry "{ Class: SmallInteger }" |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2134
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2135
    "/ the following code only works with
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2136
    "/ 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
  2137
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2138
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2139
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2140
        ^ 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
  2141
    ]. 
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2142
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2143
    len := rsltLen := digitByteArray size.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2144
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2145
    "/ 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
  2146
    "/ 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
  2147
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2148
    (digitByteArray at:len) == 16rFF ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2149
        rsltLen := len + 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2150
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2151
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2152
    result := self class basicNew numberOfDigits:rsltLen.
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2153
    result sign:newSign.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2154
    resultDigitByteArray := result digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2155
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2156
%{
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2157
    if (__isByteArray(__INST(digitByteArray))
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2158
     && __isByteArray(resultDigitByteArray)
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2159
     && __isSmallInteger(aSmallInteger)) {
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2160
        /* carry is NOT unsigned (see negation below) */
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2161
        INT __carry = __intVal(aSmallInteger);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2162
        int __index = 1;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2163
        int __len = __intVal(len);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2164
        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
  2165
        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
  2166
        INT __ptrDelta = __dst - __src;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2167
        unsigned char *__srcLast = __src + __len - 1;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2168
        unsigned char *__dstLast = __dst + __intVal(rsltLen) - 1;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2169
        unsigned char *__srcLast4;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2170
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2171
        if (__carry < 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2172
            __carry = -__carry;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2173
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2174
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2175
#if defined(__LSBFIRST) || defined(i386) || defined(alpha)
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2176
# if defined(i386) && defined(__GNUC__)
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2177
        /*
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2178
         * add long-wise
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2179
         */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2180
        __srcLast4 = __srcLast - 3;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2181
        while (__src <= __srcLast4) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2182
            unsigned int __sum;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2183
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2184
            asm ("addl %%edx,%%eax      \n
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2185
                  movl $0,%%edx         \n
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2186
                  adcl $0,%%edx"    
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2187
                    : "=d"  ((unsigned long)(__carry)),
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2188
                      "=a"  ((unsigned long)(__sum))
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2189
                    : "0"   ((unsigned long)(__carry)),
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2190
                      "1"   ((unsigned long)(((unsigned *)__src)[0])) );
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2191
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2192
            ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2193
            __src += 4;  
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2194
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2195
            if (__carry == 0) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2196
                while (__src <= __srcLast4) {
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2197
                    /* copy over words */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2198
                    ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2199
                    __src += 4;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2200
                }
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2201
                while (__src <= __srcLast) {
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2202
                    /* copy over bytes */
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2203
                    __src[__ptrDelta] = __src[0];
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2204
                    __src ++;
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2205
                }
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2206
                goto doneSource;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2207
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2208
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2209
# else 
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2210
#  if defined(i386) && defined(WIN32)
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2211
        /*
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2212
         * add long-wise
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2213
         */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2214
        __srcLast4 = __srcLast - 3;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2215
        while (__src <= __srcLast4) {
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2216
            unsigned int __sum;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2217
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2218
            __sum = ((unsigned int *)__src)[0];    
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2219
            asm {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2220
                  mov eax, __sum
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2221
                  add eax, __carry
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2222
                  mov edx, 0
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2223
                  adc edx, 0
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2224
                  mov __sum, eax
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2225
                  mov __carry, edx
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2226
                }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2227
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2228
            ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2229
            __src += 4;  
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2230
            if (__carry == 0) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2231
                while (__src <= __srcLast4) {
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2232
                    /* copy over words */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2233
                    ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2234
                    __src += 4;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2235
                }
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2236
                while (__src <= __srcLast) {
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2237
                    /* copy over bytes */
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2238
                    __src[__ptrDelta] = __src[0];
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2239
                    __src ++;
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2240
                }
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2241
                goto doneSource;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2242
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2243
        }
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2244
#  else 
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2245
#   ifdef alpha64
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2246
        /*
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2247
         * add long-wise
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2248
         */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2249
        __srcLast4 = __srcLast - 3;
4222
a2799703a8ad oops alpha fix
Claus Gittinger <cg@exept.de>
parents: 4216
diff changeset
  2250
        while (__src <= __srcLast4) {
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2251
            unsigned INT __sum;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2252
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2253
            __sum = ((unsigned int *)__src)[0] + __carry;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2254
            ((unsigned int *)(__src + __ptrDelta))[0] = __sum /* & 0xFFFF */;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2255
            __src += 4;  
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2256
            __carry = __sum >> 32;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2257
            if (__carry == 0) {
4222
a2799703a8ad oops alpha fix
Claus Gittinger <cg@exept.de>
parents: 4216
diff changeset
  2258
                while (__src <= __srcLast4) {
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2259
                    /* copy over words */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2260
                    ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2261
                    __src += 4;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2262
                }
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2263
                while (__src <= __srcLast) {
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2264
                    /* copy over bytes */
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2265
                    __src[__ptrDelta] = __src[0];
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2266
                    __src ++;
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2267
                }
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2268
                goto doneSource;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2269
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2270
        }
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2271
#   endif /* alpha64 */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2272
#  endif /* i386 & WIN32 */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2273
# endif /* i386 & GNUC */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2274
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2275
        /*
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2276
         * add short-wise
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2277
         */
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2278
        while (__src < __srcLast) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2279
            __carry += ((unsigned short *)__src)[0];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2280
            ((unsigned short *)(__src + __ptrDelta))[0] = __carry /* & 0xFFFF */;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2281
            __carry >>= 16;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2282
            __src += 2;
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
        if (__src <= __srcLast) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2285
            __carry += __src[0];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2286
            __src[__ptrDelta] = __carry /* & 0xFF */;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2287
            __carry >>= 8;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2288
            __src++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2289
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2290
#else /* not __LSBFIRST */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2291
        while (__src <= __srcLast) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2292
            __carry += __src[0];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2293
            __src[__ptrDelta] = __carry /* & 0xFF */;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2294
            __carry >>= 8;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2295
            __src++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2296
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2297
#endif /* __LSBFIRST */
4185
375439993eb7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4182
diff changeset
  2298
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2299
    doneSource: ;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2300
        __dst = __src + __ptrDelta;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2301
        while (__dst <= __dstLast) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2302
            __dst[0] = __carry /* & 0xFF */;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2303
            __carry >>= 8;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2304
            __dst++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2305
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2306
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2307
        if (__dst[-1]) {      /* lastDigit */
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2308
            RETURN (result);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2309
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2310
        ok = true;
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2311
    }
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2312
%}.
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2313
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2314
    ok ~~ true ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2315
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2316
        carry := aSmallInteger abs.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2317
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2318
        [carry ~~ 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2319
            (index <= len) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2320
                carry := (digitByteArray basicAt:index) + carry.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2321
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2322
            resultDigitByteArray basicAt:index put:(lastDigit := carry bitAnd:16rFF).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2323
            carry := carry bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2324
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2325
        ].
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
        (index <= rsltLen) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2328
            [index <= len] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2329
                resultDigitByteArray basicAt:index put:(digitByteArray basicAt:index).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2330
                index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2331
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2332
            lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2333
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2334
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2335
        lastDigit ~~ 0 ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2336
            ^ result
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2337
        ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2338
    ].
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2339
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2340
    ^ result compressed
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2341
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2342
    "Modified: 24.3.1997 / 21:32:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2343
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2344
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2345
absLess:aLargeInteger
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2346
    "return true, if abs(self) < abs(theArgument).
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2347
     This handles unnormalized largeIntegers."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2348
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2349
    |myLen "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2350
     otherLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2351
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2352
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2353
     otherDigitByteArray |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2354
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2355
    myLen := digitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2356
    otherDigitByteArray := aLargeInteger digits.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2357
    otherLen := otherDigitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2358
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2359
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2360
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2361
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2362
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2363
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2364
    [myLen > 0 and:[(digitByteArray basicAt:myLen) == 0]] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2365
	myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2366
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2367
    [otherLen > 0 and:[(otherDigitByteArray basicAt:otherLen) == 0]] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2368
	otherLen := otherLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2369
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2370
    (myLen < otherLen) ifTrue:[^ true].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2371
    (myLen > otherLen) ifTrue:[^ false].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2372
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2373
    [myLen > 0] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2374
	d1 := digitByteArray basicAt:myLen.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2375
	d2 := otherDigitByteArray basicAt:myLen.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2376
	d1 == d2 ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2377
	    (d1 < d2) ifTrue:[^ true].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2378
	    ^ false
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2379
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2380
	myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2381
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2382
    ^ false
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2383
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2384
    "Modified: / 3.5.1999 / 08:06:28 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2385
    "Modified: / 8.5.1999 / 18:37:11 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2386
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2387
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2388
absLessEq:aLargeInteger
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2389
    "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
  2390
     This handles unnormalized largeIntegers."
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2391
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2392
    |myLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2393
     otherLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2394
     d1   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2395
     d2   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2396
     otherDigitByteArray |
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2397
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2398
    myLen := digitByteArray size.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2399
    otherDigitByteArray := aLargeInteger digits.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2400
    otherLen := otherDigitByteArray size.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2401
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2402
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2403
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2404
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2405
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2406
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2407
    [(digitByteArray basicAt:myLen) == 0] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2408
	myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2409
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2410
    [(otherDigitByteArray basicAt:otherLen) == 0] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2411
	otherLen := otherLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2412
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2413
    (myLen < otherLen) ifTrue:[^ true].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2414
    (myLen > otherLen) ifTrue:[^ false].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2415
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2416
    [myLen > 0] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2417
	d1 := digitByteArray basicAt:myLen.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2418
	d2 := otherDigitByteArray basicAt:myLen.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2419
	d1 == d2 ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2420
	    (d1 < d2) ifTrue:[^ true].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2421
	    ^ false.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2422
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2423
	myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2424
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2425
    ^ true
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2426
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2427
    "Created: / 13.2.1998 / 12:19:45 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2428
    "Modified: / 30.4.1999 / 12:46:31 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2429
    "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
  2430
!
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2431
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2432
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
  2433
    "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
  2434
     with sign: newSign.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2435
     The result is normalized. The argument must be a largeInteger
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2436
     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
  2437
     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
  2438
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2439
    |result done
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2440
     otherDigitByteArray resultDigitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2441
     len1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2442
     len2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2443
     index  "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2444
     borrow "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2445
     diff   "{ Class: SmallInteger }"
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2446
     carry  "{ Class: SmallInteger }" 
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2447
     lastDigit   
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2448
     lResult ok|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2449
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2450
    len1 := digitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2451
    otherDigitByteArray := aLargeInteger digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2452
    len2 := otherDigitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2453
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2454
    len1 > len2 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2455
        lResult := len1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2456
    ] ifFalse:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2457
        lResult := (len1 max: len2) + 1.
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2458
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2459
    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
  2460
    result sign:newSign.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2461
    resultDigitByteArray := result digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2462
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2463
    lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2464
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2465
%{
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2466
    OBJ _digitByteArray = __INST(digitByteArray);
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2467
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2468
    if (__isByteArray(_digitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2469
     && __isByteArray(otherDigitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2470
     && __isByteArray(resultDigitByteArray)) {
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2471
        int __len1 = __intVal(len1);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2472
        int __len2 = __intVal(len2);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2473
        int __minLen = __len1 < __len2 ? __len1 : __len2;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2474
        int __index, __borrow = 0, __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2475
        unsigned char *__myDigits, *__otherDigits, *__resultDigits;
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2476
        
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2477
        ok = true;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2478
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2479
        __resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2480
        __otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2481
        __myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2482
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2483
        __index = 1;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2484
#if defined(i386) || defined(__LSBFIRST)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2485
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2486
         * subtract short-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2487
         */
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2488
        while (__index < __minLen) {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2489
            __diff = ((unsigned short *)(__myDigits+__index-1))[0] 
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2490
                     - ((unsigned short *)(__otherDigits+__index-1))[0]
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2491
                     - __borrow;
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2492
            if (__diff >= 0) {
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2493
                __borrow = 0;
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2494
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2495
                __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2496
                /* __diff += 0x10000; */
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2497
            }
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2498
            ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2499
            __index += 2;
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2500
        }
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2501
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2502
        if (__index == __minLen) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2503
            /* one of the operands has odd length - cannot continue short-wise */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2504
        } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2505
            if (__len1 > __len2) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2506
                while (__index < __len1) {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2507
                    __diff = ((unsigned short *)(__myDigits+__index-1))[0] - __borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2508
                    if (__diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2509
                        __borrow = 0;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2510
                        ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2511
                        __index += 2;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2512
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2513
                        /* copy over rest */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2514
                        while (__index < __len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2515
                            ((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
  2516
                            __index+=2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2517
                        }
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2518
                        if (__index <= __len1) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2519
                            __resultDigits[__index-1] = __myDigits[__index-1];
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2520
                            __index++;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2521
                        }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2522
                        break;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2523
                    }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2524
                    __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2525
                    /* __diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2526
                    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2527
                    __index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2528
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2529
            } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2530
                if (__len2 > __len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2531
                    while (__index < __len2) {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2532
                        __diff = 0 - ((unsigned short *)(__otherDigits+__index-1))[0] - __borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2533
                        if (__diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2534
                            __borrow = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2535
                        } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2536
                            __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2537
                            /* __diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2538
                        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2539
                        ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2540
                        __index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2541
                    }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2542
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2543
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2544
        }
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2545
#endif
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2546
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2547
         * subtract byte-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2548
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2549
        while (__index <= __minLen) {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2550
            __diff = __myDigits[__index-1] - __otherDigits[__index-1] - __borrow;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2551
            if (__diff >= 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2552
                __borrow = 0;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2553
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2554
                __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2555
                /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2556
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2557
            __resultDigits[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2558
            __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2559
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2560
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2561
        if (__len1 > __len2) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2562
            while (__index <= __len1) {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2563
                __diff = __myDigits[__index-1] - __borrow;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2564
                if (__diff >= 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2565
                    __borrow = 0;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2566
                    /* copy over rest */
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2567
                    __resultDigits[__index-1] = __diff;
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2568
                    __index++;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2569
                    while (__index <= __len1) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2570
                        __resultDigits[__index-1] = __myDigits[__index-1];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2571
                        __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2572
                    }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2573
                    break;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2574
                }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2575
                __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2576
                /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2577
                __resultDigits[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2578
                __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2579
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2580
        } else {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2581
            if (__len2 > __len1) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2582
                while (__index <= __len2) {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2583
                    __diff = 0 - __otherDigits[__index-1] - __borrow;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2584
                    if (__diff >= 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2585
                        __borrow = 0;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2586
                    } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2587
                        __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2588
                        /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2589
                    }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2590
                    __resultDigits[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2591
                    __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2592
                }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2593
            }
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
        borrow = __MKSMALLINT(__borrow);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2596
        index = __MKSMALLINT(__index);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2597
        lastDigit = __MKSMALLINT(__resultDigits[__index-1-1]);
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2598
    }
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2599
%}.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2600
    ok == true ifFalse:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2601
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2602
        borrow := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2603
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2604
        done := false.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2605
        [done] whileFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2606
            diff := borrow.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2607
            (index <= len1) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2608
                diff := diff + (digitByteArray basicAt:index).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2609
                (index <= len2) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2610
                    diff := diff - (otherDigitByteArray basicAt:index)
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2611
                ]
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2612
            ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2613
                (index <= len2) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2614
                    diff := diff - (otherDigitByteArray basicAt:index)
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2615
                ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2616
                    "end reached"
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2617
                    done := true
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2618
                ]
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2619
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2620
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2621
            "/ workaround for
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2622
            "/ gcc code generator bug
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2623
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2624
            (diff >= 0) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2625
                borrow := 0
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2626
            ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2627
                borrow := -1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2628
                diff := diff + 16r100
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2629
            ].
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2630
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2631
    "/        (diff < 0) ifTrue:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2632
    "/            borrow := -1.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2633
    "/            diff := diff + 16r100
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2634
    "/        ] ifFalse:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2635
    "/            borrow := 0
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2636
    "/        ].
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2637
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2638
            resultDigitByteArray basicAt:index put:diff.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2639
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2640
        ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2641
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2642
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2643
    (borrow ~~ 0) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2644
        "/ must generate 255's complement
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2645
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2646
        result sign:-1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2647
        [index <= lResult] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2648
            resultDigitByteArray basicAt:index put:16rFF.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2649
            index := index + 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2650
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2651
        index := resultDigitByteArray size.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2652
        [index > 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2653
            resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2654
            index := index - 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2655
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2656
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2657
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2658
        carry := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2659
        [carry ~~ 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2660
            (index <= lResult) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2661
                carry := (resultDigitByteArray basicAt:index) + carry.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2662
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2663
            resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2664
            carry := carry bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2665
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2666
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2667
        lastDigit := resultDigitByteArray basicAt:(resultDigitByteArray size).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2668
    ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2669
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2670
    (lastDigit ~~ 0) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2671
        ^ result
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2672
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2673
    ^ result compressed
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2674
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2675
    "Modified: 5.11.1996 / 14:09:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2676
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2677
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2678
absMod:anInteger
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2679
    "return a LargeIntegers representing
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2680
     abs(self) \\ abs(theArgument).
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2681
     Used as a helper for \\ and rem:"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2682
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2683
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2684
    |dividend divisor 
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2685
     shift "{ Class: SmallInteger }" |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2686
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2687
    anInteger == 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2688
	^ DivisionByZeroSignal raise
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2689
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2690
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2691
    self = anInteger ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2692
	^ 0
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2693
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2694
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2695
    shift := self highBit - anInteger highBit.
4140
3e66cfaae7a7 Some fixes for absMod: on a negative number
Stefan Vogel <sv@exept.de>
parents: 4139
diff changeset
  2696
    dividend := self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2697
    shift < 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2698
	^ dividend.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2699
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  2700
    shift == 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2701
	divisor := anInteger simpleDeepCopy.
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  2702
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2703
	divisor := anInteger bitShift:shift.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2704
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2705
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2706
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2707
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2708
    [shift > 0] whileTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2709
	(dividend absLess:divisor) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2710
	    (dividend absSubtract: divisor) ifFalse:[ "result == 0"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2711
		^ dividend compressed            
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2712
	    ].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2713
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2714
	shift := shift - 1.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  2715
	divisor div2.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2716
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2717
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2718
    ^ dividend compressed
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2719
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2720
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2721
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absMod:4000000001] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2722
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absDivMod:4000000001] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2723
     16000000000 absMod:4000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2724
     16000000000 absMod:3000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2725
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2726
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2727
    "Modified: / 5.11.1996 / 18:40:24 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2728
    "Created: / 27.4.1999 / 19:45:44 / stefan"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2729
    "Modified: / 3.5.1999 / 08:41:39 / stefan"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2730
!
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2731
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2732
absMul:aLargeInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2733
    "return a LargeInteger representing abs(self) * abs(theArgument)"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2734
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2735
    |result otherDigitByteArray resultDigitByteArray ok
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2736
     idx      "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2737
     carry    "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2738
     len1     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2739
     len2     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2740
     dstIndex "{ Class: SmallInteger }"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2741
     prod     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2742
     v        "{ Class: SmallInteger }"|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2743
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2744
    len1 := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2745
    otherDigitByteArray := aLargeInteger digits.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2746
    len2 := otherDigitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2747
4151
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
  2748
    result := LargeInteger basicNew numberOfDigits:(len1 + len2).
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2749
    resultDigitByteArray := result digits.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2750
    ok := false.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2751
%{
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  2752
    if (__isByteArray(__INST(digitByteArray))
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2753
     && __isByteArray(otherDigitByteArray)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2754
     && __isByteArray(resultDigitByteArray)
250
a5deb61ffdac *** empty log message ***
claus
parents: 175
diff changeset
  2755
     && __bothSmallInteger(len1, len2)) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2756
        unsigned char *myBytes = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2757
        unsigned char *otherBytes = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2758
        unsigned char *resultBytes = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2759
        unsigned char *_p1, *_p2, *_pResult, *_pResult0, *_pResult1, *_p1Last, *_p2Last;
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2760
        unsigned char *_pResultLast3;
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2761
        unsigned INT _v;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2762
        int _len1 = __intVal(len1);
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2763
        int _len2 = __intVal(len2);
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2764
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2765
        _p1Last = myBytes    + _len1 - 1;  /* the last byte */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2766
        _p2Last = otherBytes + _len2 - 1;  /* the last byte */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2767
        _pResult0 = resultBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2768
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2769
        /*
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2770
         *        aaa...aaa      f1[0] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2771
         *       bbb...bbb       f1[1] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2772
         *      ccc...ccc        f1[2] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2773
         *     ...
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2774
         *    xxx...xxx          f1[high] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2775
         *
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2776
         * start short-wise
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2777
         * bounds: (16rFFFF * 16rFFFF) + 16rFFFF -> FFFF0000
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2778
         */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2779
        _p1 = myBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2780
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2781
#if defined(alpha64)
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2782
        /* loop over ints of f1 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2783
        for (; _p1 < _p1Last-2; _p1 += 4, _pResult0 += 4) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2784
            unsigned INT word1 = ((unsigned int *)_p1)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2785
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2786
            _pResult = _pResult0;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2787
            _p2 = otherBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2788
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2789
            /* loop over ints of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2790
            while (_p2 < (_p2Last-2)) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2791
                _v = (word1 * ((unsigned int *)_p2)[0]) + ((unsigned int *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2792
                ((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2793
                _v >>= 32; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2794
                _pResult += 4;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2795
                if (_v) {
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2796
                    /* distribute carry - int-wise, then byte-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2797
                    _pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2798
                    for (_pResult1 = _pResult; _v; _pResult1 += 4) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2799
                        if (_pResult1 > _pResultLast3) break;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2800
                        _v += ((unsigned int *)_pResult1)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2801
                        ((unsigned int *)_pResult1)[0] = _v /* & 0xFFFFFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2802
                        _v >>= 32;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2803
                    }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2804
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2805
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2806
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2807
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2808
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2809
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2810
                _p2 += 4;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2811
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2812
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2813
            /* possible odd highByte of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2814
            while (_p2 <= _p2Last) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2815
                _v = (word1 * _p2[0]) + ((unsigned int *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2816
                ((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2817
                _v >>= 32; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2818
                _pResult += 4;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2819
                if (_v) {
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2820
                    /* distribute carry - int-wise, then byte-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2821
                    _pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2822
                    for (_pResult1 = _pResult; _v; _pResult1 += 4) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2823
                        if (_pResult1 > _pResultLast3) break;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2824
                        _v += ((unsigned int *)_pResult1)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2825
                        ((unsigned int *)_pResult1)[0] = _v /* & 0xFFFFFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2826
                        _v >>= 32;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2827
                    }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2828
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2829
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2830
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2831
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2832
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2833
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2834
                _p2++;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2835
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2836
        }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2837
#endif /* alpha64 */
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2838
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2839
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2840
        /* loop over shorts of f1 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2841
        for (; _p1 < _p1Last; _p1 += 2, _pResult0 += 2) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2842
            unsigned int short1 = ((unsigned short *)_p1)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2843
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2844
            _pResult = _pResult0;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2845
            _p2 = otherBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2846
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2847
            /* loop over shorts of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2848
            while (_p2 < _p2Last) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2849
                _v = (short1 * ((unsigned short *)_p2)[0]) + ((unsigned short *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2850
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2851
                _v >>= 16; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2852
                _pResult += 2;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2853
                if (_v) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2854
                    /* distribute carry */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2855
                    for (_pResult1 = _pResult; _v; _pResult1++) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2856
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2857
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2858
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2859
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2860
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2861
                _p2 += 2;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2862
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2863
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2864
            /* possible odd highByte of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2865
            if (_p2 <= _p2Last) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2866
                _v = (short1 * _p2[0]) + ((unsigned short *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2867
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2868
                _v >>= 16; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2869
                _pResult += 2;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2870
                if (_v) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2871
                    /* distribute carry */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2872
                    for (_pResult1 = _pResult; _v; _pResult1++) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2873
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2874
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2875
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2876
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2877
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2878
                _p2++;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2879
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2880
        }
4164
59da946fb307 oops - the short-multiply optimization is only ok
Claus Gittinger <cg@exept.de>
parents: 4163
diff changeset
  2881
#endif /* LSBFIRST */
59da946fb307 oops - the short-multiply optimization is only ok
Claus Gittinger <cg@exept.de>
parents: 4163
diff changeset
  2882
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2883
        /* possible odd highByte of f1 (or byteLoop, if not LSBFIRST) */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2884
        for (; _p1 <= _p1Last; _p1++, _pResult0++) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2885
            unsigned int byte1 = _p1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2886
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2887
            _pResult = _pResult0;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2888
            _p2 = otherBytes;
4175
ecbeb3109903 fixed absMul: (for non-LSBFIRST)
Claus Gittinger <cg@exept.de>
parents: 4174
diff changeset
  2889
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2890
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2891
            /* loop over shorts of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2892
            while (_p2 < _p2Last) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2893
                _v = (byte1 * ((unsigned short *)_p2)[0]) + ((unsigned short *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2894
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2895
                _v >>= 16; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2896
                _pResult += 2;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2897
                if (_v) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2898
                    /* distribute carry */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2899
                    for (_pResult1 = _pResult; _v; _pResult1++) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2900
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2901
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2902
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2903
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2904
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2905
                _p2 += 2;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2906
            }
4164
59da946fb307 oops - the short-multiply optimization is only ok
Claus Gittinger <cg@exept.de>
parents: 4163
diff changeset
  2907
#endif /* __LSBFIRST */
59da946fb307 oops - the short-multiply optimization is only ok
Claus Gittinger <cg@exept.de>
parents: 4163
diff changeset
  2908
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2909
            /* possible odd highByte of f2 (or byteLoop, if not LSBFIRST) */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2910
            while (_p2 <= _p2Last) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2911
                _v = (byte1 * _p2[0]) + _pResult[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2912
                _pResult[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2913
                _v >>= 8; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2914
                _pResult++;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2915
                if (_v) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2916
                    /* distribute carry */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2917
                    for (_pResult1 = _pResult; _v; _pResult1++) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2918
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2919
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2920
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2921
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2922
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2923
                _p2++;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2924
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2925
        }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2926
        ok = true;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2927
    }
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2928
%}.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2929
    ok ifFalse:[
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2930
        1 to:len1 do:[:index1 |
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2931
            1 to:len2 do:[:index2 |
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2932
                dstIndex := index1 + index2 - 1.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2933
                prod := (digitByteArray basicAt:index1) * (otherDigitByteArray basicAt:index2).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2934
                prod := prod + (resultDigitByteArray basicAt:dstIndex).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2935
                resultDigitByteArray basicAt:dstIndex put:(prod bitAnd:16rFF).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2936
                carry := prod bitShift:-8.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2937
                carry ~~ 0 ifTrue:[
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2938
                    idx := dstIndex + 1.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2939
                    [carry ~~ 0] whileTrue:[
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2940
                        v := (resultDigitByteArray basicAt:idx) + carry.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2941
                        resultDigitByteArray basicAt:idx put:(v bitAnd:255).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2942
                        carry := v bitShift:-8.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2943
                        idx := idx + 1
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2944
                    ]
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2945
                ]
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2946
            ]
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  2947
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2948
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2949
    ^ result compressed
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2950
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2951
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2952
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
  2953
    "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
  2954
     with sign: newSign.
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2955
     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
  2956
     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
  2957
     This is a helper for addition and subtraction - not for public use."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2958
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2959
    |result done otherDigitByteArray resultDigitByteArray
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2960
     len1   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2961
     len2   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2962
     newLen "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2963
     index  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2964
     carry  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2965
     sum    "{ Class: SmallInteger }" |
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2966
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2967
    otherDigitByteArray := aLargeInteger digits.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2968
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2969
%{
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2970
    OBJ _digitByteArray = __INST(digitByteArray);
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2971
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2972
    if (__isByteArray(_digitByteArray)
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  2973
     && __isByteArray(otherDigitByteArray)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2974
        int _len1, _len2, _newLen;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2975
        unsigned char *_myDigits, *_otherDigits, *_newDigits;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2976
        int _index, _carry;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  2977
        int _comLen, _comLen3;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2978
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2979
        _len1 = __byteArraySize(_digitByteArray);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2980
        _len2 = __byteArraySize(otherDigitByteArray);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2981
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2982
        _otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2983
        _myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2984
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2985
        if (_len1 < _len2) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2986
            _comLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2987
            _newLen = _len2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2988
            if (_otherDigits[_len2 - 1] == 0xFF) _newLen++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2989
        } else if (_len2 < _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2990
            _comLen = _len2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2991
            _newLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2992
            if (_myDigits[_len1 - 1] == 0xFF) _newLen++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2993
        } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2994
            /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2995
             * there can only be an overflow from the high bytes,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2996
             * if their sum is >= 255
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  2997
             * (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
  2998
             */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2999
            _newLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3000
            if ((_otherDigits[_len2 - 1] + _myDigits[_len1 - 1]) >= 0xFF) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3001
                _newLen++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3002
            } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3003
                if (_newLen == sizeof(INT)) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3004
                    /* 
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3005
                     * two word-sized numbers, no carry - a very common case ...
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3006
                     */
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3007
#if defined(__LSB_FIRST) || defined(i386) || defined(alpha)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3008
                    unsigned INT _sum = *(unsigned INT *)_otherDigits + *(unsigned INT *)_myDigits;
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3009
#else
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3010
                    unsigned INT _sum = __longIntVal(self) + __longIntVal(aLargeInteger);
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3011
#endif /* not LSB_FIRST */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3012
                    RETURN (__MKULARGEINT(_sum));
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3013
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3014
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3015
            _comLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3016
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3017
        resultDigitByteArray = __BYTEARRAY_UNINITIALIZED_NEW_INT(_newLen);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3018
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3019
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3020
         * must refetch - GC could have been invoked
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3021
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3022
        _digitByteArray = __INST(digitByteArray);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3023
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3024
        _myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3025
        _otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3026
        _newDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3027
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3028
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3029
         * add them ...
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3030
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3031
        _index = 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3032
        _carry = 0;
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3033
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3034
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  3035
# ifdef INT64
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3036
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3037
         * have a 64bit integer type;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3038
         * add long-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3039
         * accessing bytes at: [index-1][index][index+1][index+1]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3040
         */
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3041
        _comLen3 = _comLen - 3;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3042
        while (_index <= _comLen3) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3043
            UINT64 _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3044
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3045
            _sum = _carry
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3046
                    + *(unsigned *)(&(_myDigits[_index - 1]))
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3047
                    + *(unsigned *)(&(_otherDigits[_index - 1]));
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3048
            _carry = _sum >> 32;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3049
            /* _sum = _sum & 0xFFFFFFFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3050
            ((unsigned int *)(&(_newDigits[_index - 1])))[0] = _sum;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3051
            _index += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3052
        }
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3053
# else
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3054
#  if defined(i386) && defined(__GNUC__)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3055
        /*
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3056
         * add long-wise
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3057
         * accessing bytes at: [index-1][index][index+1][index+1]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3058
         */
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3059
        _comLen3 = _comLen - 3;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3060
        while (_index <= _comLen3) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3061
            unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3062
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3063
            asm ("addl %%edx,%%eax      \n   
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3064
                  movl $0,%%edx         \n   
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3065
                  adcl $0,%%edx         \n   
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3066
                  addl %4,%%eax         \n   
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3067
                  adcl $0,%%edx"    
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3068
                    : "=d"  (_carry),
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3069
                      "=a"  (_sum)
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3070
                    : "0"   (_carry),
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3071
                      "1"   (((unsigned int *)(&(_myDigits[_index - 1])))[0]), 
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3072
                      "rm"  (((unsigned int *)(&(_otherDigits[_index - 1])))[0]) 
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3073
                );
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3074
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3075
            ((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3076
            _index += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3077
        }
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3078
#  endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  3079
# endif
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3080
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3081
         * add short-wise
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3082
         * accessing bytes at: [index-1][index]
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3083
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3084
        while (_index < _comLen) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3085
            unsigned int _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3086
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3087
            _sum = _carry 
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3088
                   + *(unsigned short *)(&(_myDigits[_index - 1]))
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3089
                   + *(unsigned short *)(&(_otherDigits[_index - 1]));
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3090
            _carry = _sum >> 16;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3091
            /* _sum = _sum & 0xFFFF; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3092
            *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3093
            _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3094
        }
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  3095
#endif
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  3096
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3097
        /*
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3098
         * add byte-wise
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3099
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3100
        while (_index <= _comLen) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3101
            unsigned int _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3102
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3103
            _sum = _carry 
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3104
                   + _myDigits[_index - 1] 
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3105
                   + _otherDigits[_index - 1];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3106
            _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3107
            /* _sum = _sum & 0xFF; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3108
            _newDigits[_index - 1] = _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3109
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3110
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3111
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3112
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3113
         * rest
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3114
         */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3115
        if (_len1 > _len2) {
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3116
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3117
            if (_index <= _len1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3118
                if ((_index - 1) & 1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3119
                    /* odd byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3120
                    unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3121
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3122
                    _sum = _carry + _myDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3123
                    _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3124
                    /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3125
                    _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3126
                    _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3127
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3128
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3129
                while (_index < _len1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3130
                    /* shorts */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3131
                    unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3132
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3133
                    _sum = _carry + *(unsigned short *)(&(_myDigits[_index - 1]));
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3134
                    _carry = _sum >> 16;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3135
                    /* _sum = _sum & 0xFFFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3136
                    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3137
                    _index += 2;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3138
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3139
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3140
                if (_index <= _len1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3141
                    /* last byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3142
                    unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3143
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3144
                    _sum = _carry + _myDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3145
                    _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3146
                    /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3147
                    _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3148
                    _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3149
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3150
            }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3151
#else
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3152
            while (_index <= _len1) {
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3153
                unsigned int _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3154
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3155
                _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
  3156
                _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3157
                /* _sum = _sum & 0xFF; */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3158
                _newDigits[_index - 1] = _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3159
                _index++;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3160
            }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3161
#endif /* not LSB */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3162
        } else {
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3163
            if (_len2 > _len1) {
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3164
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3165
                if (_index <= _len2) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3166
                    if ((_index - 1) & 1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3167
                        /* odd byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3168
                        unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3169
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3170
                        _sum = _carry + _otherDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3171
                        _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3172
                        /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3173
                        _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3174
                        _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3175
                    }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3176
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3177
                    while (_index < _len2) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3178
                        /* shorts */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3179
                        unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3180
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3181
                        _sum = _carry + *(unsigned short *)(&(_otherDigits[_index - 1]));
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3182
                        _carry = _sum >> 16;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3183
                        /* _sum = _sum & 0xFFFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3184
                        *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3185
                        _index += 2;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3186
                    }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3187
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3188
                    if (_index <= _len2) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3189
                        /* last byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3190
                        unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3191
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3192
                        _sum = _carry + _otherDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3193
                        _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3194
                        /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3195
                        _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3196
                        _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3197
                    }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3198
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3199
#else
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3200
                while (_index <= _len2) {
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3201
                    unsigned int _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3202
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3203
                    _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
  3204
                    _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3205
                    /* _sum = _sum & 0xFF; */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3206
                    _newDigits[_index - 1] = _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3207
                    _index++;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3208
                }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3209
#endif /* not LSB */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3210
            }
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3211
        }
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3212
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3213
        while (_index <= _newLen) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3214
            unsigned int _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3216
            _sum = _carry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3217
            _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3218
            /* _sum = _sum & 0xFF; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3219
            _newDigits[_index - 1] = _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3220
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3221
        }
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3222
    }
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3223
%}.
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3224
    resultDigitByteArray notNil ifTrue:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3225
        result := self class basicNew.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3226
        result setDigits:resultDigitByteArray.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3227
        result sign:newSign.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3228
    ] ifFalse:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3229
        len1 := digitByteArray size.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3230
        len2 := otherDigitByteArray size.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3231
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3232
        "/ earlier versions estimated the newLength as:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3233
        "/ (len1 max:len2) + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3234
        "/ and reduced the result.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3235
        "/ however, if one of the addends is smaller,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3236
        "/ the result will never require another digit,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3237
        "/ if the highest digit of the larger addent is
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3238
        "/ not equal to 255. Therefore, in most cases,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3239
        "/ we can avoid the computation and resizing 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3240
        "/ in #reduced.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3241
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3242
        len1 < len2 ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3243
            newLen := len2.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3244
            (otherDigitByteArray at:len2) == 16rFF ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3245
                newLen := newLen + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3246
            ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3247
        ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3248
            len2 < len1 ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3249
                newLen := len1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3250
                (digitByteArray at:len1) == 16rFF ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3251
                    newLen := newLen + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3252
                ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3253
            ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3254
                newLen := len1 + 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3255
            ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3256
        ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3257
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3258
        result := self class basicNew numberOfDigits:newLen.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3259
        result sign:newSign.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3260
        resultDigitByteArray := result digits.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3261
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3262
        index := 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3263
        carry := 0.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3264
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3265
        done := false.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3266
        [done] whileFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3267
            sum := carry.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3268
            (index <= len1) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3269
                sum := sum + (digitByteArray basicAt:index).
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3270
                (index <= len2) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3271
                    sum := sum + (otherDigitByteArray basicAt:index)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3272
                ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3273
            ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3274
                (index <= len2) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3275
                    sum := sum + (otherDigitByteArray basicAt:index)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3276
                ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3277
                    "end reached"
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3278
                    done := true
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3279
                ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3280
            ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3281
            (sum >= 16r100) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3282
                carry := 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3283
                sum := sum - 16r100
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3284
            ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3285
                carry := 0
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3286
            ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3287
            resultDigitByteArray basicAt:index put:sum.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3288
            index := index + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3289
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3290
    ].
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3291
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3292
    ^ result compressed
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3293
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3294
    "Modified: 11.8.1997 / 03:23:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3295
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3296
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3297
absSubtract:aLargeInteger
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3298
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3299
        destructively subtract aLargeInteger from myself
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3300
        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
  3301
        (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
  3302
         on the receiver)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3303
        Only allowed for positive receiver and argument
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3304
        The receiver must be >= the argument.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3305
        The receiver must be a temporary scratch-number"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3306
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3307
    |otherDigitByteArray
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3308
     len1   "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3309
     len2   "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3310
     index  "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3311
     borrow "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3312
     diff   "{ Class: SmallInteger }"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3313
     notZero
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3314
    |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3315
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3316
    notZero := false.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3317
    len1 := digitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3318
    otherDigitByteArray := aLargeInteger digits.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3319
    len2 := otherDigitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3320
    len2 > len1 ifTrue:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3321
        [(otherDigitByteArray at:len2) == 0] whileTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3322
            len2 := len2 - 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3323
        ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3324
        len2 > len1 ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3325
            self halt "/ may not be called that way
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3326
        ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3327
    ].
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3328
    "/ knowing that len2 is <= len1
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3329
%{
4189
Claus Gittinger <cg@exept.de>
parents: 4188
diff changeset
  3330
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3331
    OBJ _digitByteArray = __INST(digitByteArray);
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3332
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3333
    if (__isByteArray(_digitByteArray)
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3334
     && __isByteArray(otherDigitByteArray)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3335
        int _len1 = __intVal(len1), 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3336
            _len2 = __intVal(len2);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3337
        unsigned char *_myDigits, *_otherDigits;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3338
        int _index = 1, _borrow = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3339
        int _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3340
        int anyBitNonZero = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3341
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3342
        _otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3343
        _myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3344
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3345
#if defined(i386) || defined(__LSBFIRST)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3346
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3347
         * subtract short-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3348
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3349
        while (_index < _len2) {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3350
            _diff = ((unsigned short *)(_myDigits+_index-1))[0]
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3351
                    - ((unsigned short *)(_otherDigits+_index-1))[0]
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3352
                    - _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3353
            if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3354
                _borrow = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3355
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3356
                _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3357
                /* _diff += 0x10000; */
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
            ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3360
            anyBitNonZero |= (_diff & 0xFFFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3361
            _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3362
        }
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3363
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3364
        if (_index <= _len2) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3365
            /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3366
             * cannot continue with shorts - there is an odd number of
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3367
             * bytes in the minuent
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3368
             */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3369
        } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3370
            while (_index < _len1) {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3371
                _diff = ((unsigned short *)(_myDigits+_index-1))[0] - _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3372
                if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3373
                    /* _borrow = 0; */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3374
                    ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3375
                    anyBitNonZero |= (_diff & 0xFFFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3376
                    _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3377
                    while (_index < _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3378
                        anyBitNonZero |= ((unsigned short *)(_myDigits+_index-1))[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3379
                        _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3380
                    }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3381
                    /* last odd index */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3382
                    if (_index <= _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3383
                        anyBitNonZero |= _myDigits[_index - 1];;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3384
                        _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3385
                    }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3386
                    RETURN (anyBitNonZero ? true : false);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3387
                }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3388
                _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3389
                /* _diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3390
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3391
                ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3392
                anyBitNonZero |= (_diff & 0xFFFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3393
                _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3394
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3395
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3396
#endif
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3397
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3398
         * subtract byte-wise
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
        while (_index <= _len2) {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3401
            _diff = _myDigits[_index - 1];
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3402
                    - _otherDigits[_index - 1]
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3403
                    - _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3404
            if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3405
                _borrow = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3406
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3407
                _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3408
                /* _diff += 0x100; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3409
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3410
            _myDigits[_index - 1] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3411
            anyBitNonZero |= (_diff & 0xFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3412
            _index++;
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
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3415
        while (_index <= _len1) {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3416
            _diff = _myDigits[_index - 1] - _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3417
            if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3418
                /* _borrow = 0; */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3419
                _myDigits[_index - 1] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3420
                anyBitNonZero |= (_diff & 0xFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3421
                _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3422
                while (_index <= _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3423
                    anyBitNonZero |= _myDigits[_index - 1];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3424
                    _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3425
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3426
                break;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3427
            }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3428
            _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3429
            /* _diff += 0x100; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3430
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3431
            _myDigits[_index - 1] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3432
            anyBitNonZero |= (_diff & 0xFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3433
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3434
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3435
        RETURN (anyBitNonZero ? true : false);
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3436
    }
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3437
%}.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3438
    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
  3439
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3440
"/    index := 1.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3441
"/    borrow := 0.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3442
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3443
"/    [index <= len1] whileTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3444
"/        diff := borrow.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3445
"/        diff := diff + (digitByteArray basicAt:index).
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3446
"/        index <= len2 ifTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3447
"/            diff := diff - (otherDigitByteArray basicAt:index).
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3448
"/        ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3449
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3450
"/        "/ workaround for
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3451
"/        "/ gcc code generator bug
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3452
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3453
"/        (diff >= 0) ifTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3454
"/            borrow := 0
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3455
"/        ] ifFalse:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3456
"/            borrow := -1.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3457
"/            diff := diff + 16r100
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3458
"/        ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3459
"/        diff ~~ 0 ifTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3460
"/            notZero := true
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3461
"/        ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3462
"/        digitByteArray basicAt:index put:diff.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3463
"/        index := index + 1
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3464
"/    ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3465
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3466
"/    ^ notZero
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3467
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3468
    "Created: / 5.11.1996 / 16:23:47 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3469
    "Modified: / 5.11.1996 / 18:56:50 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3470
    "Modified: / 27.4.1999 / 18:08:23 / stefan"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3471
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3472
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3473
div2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3474
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3475
       destructively divide the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3476
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3477
%{  /* NOCONTEXT */
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3478
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3479
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3480
    if (__isByteArray(__digits)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3481
        int __nBytes = __byteArraySize(__digits);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3482
        unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3483
        unsigned INT __this, __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3484
        int __idx;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3485
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3486
        if (__nBytes == 1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3487
            __bp[0] >>= 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3488
            RETURN (self);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3489
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3490
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3491
        __idx = 1;
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3492
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3493
#if defined(alpha64)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3494
        if (sizeof(unsigned INT) == 8) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3495
            int __endIndex = __nBytes - 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3496
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3497
            if (__idx < __endIndex) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3498
                __this = ((unsigned INT *)__bp)[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3499
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3500
                while (__idx < __endIndex) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3501
                    __next = ((unsigned INT *)__bp)[1];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3502
                    __this = (__this >> 1) /* & 0x7FFFFFFFFFFFFFF */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3503
                    __this |= __next << 63;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3504
                    ((unsigned INT *)__bp)[0] = __this;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3505
                    __this = __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3506
                    __bp += 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3507
                    __idx += 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3508
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3509
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3510
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3511
#else
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3512
# if defined(__LSBFIRST) || defined(i386) 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3513
        if (sizeof(unsigned INT) == 4) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3514
            int __endIndex = __nBytes - 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3515
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3516
            if (__idx < __endIndex) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3517
                __this = ((unsigned INT *)__bp)[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3518
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3519
                while (__idx < __endIndex) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3520
                    __next = ((unsigned INT *)__bp)[1];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3521
                    __this = (__this >> 1) /* & 0x7FFFFFF */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3522
                    __this |= __next << 31;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3523
                    ((unsigned INT *)__bp)[0] = __this;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3524
                    __this = __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3525
                    __bp += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3526
                    __idx += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3527
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3528
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3529
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3530
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  3531
#endif
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3532
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3533
        __this = __bp[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3534
        while (__idx < __nBytes) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3535
            __next = __bp[1];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3536
            __this >>= 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3537
            __this |= __next << 7;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3538
            __bp[0] = __this;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3539
            __this = __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3540
            __bp++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3541
            __idx++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3542
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3543
        __bp[0] = __this >> 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3544
        RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3545
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3546
%}.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3547
    self primitiveFailed
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3548
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3549
    "
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3550
     100000 asLargeInteger div2      
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3551
     1000000000000000000000000000 div2 
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3552
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3553
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3554
    "Modified: 5.11.1996 / 16:12:56 / cg"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3555
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3556
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3557
mul2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3558
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3559
       destructively multiply the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3560
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3561
    |nBytes "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3562
     b      "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3563
     t|
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3564
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3565
    nBytes := digitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3566
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3567
    b := digitByteArray at:nBytes.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3568
    (b bitAnd:16r80) ~~ 0 ifTrue:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3569
        "/ need another byte
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3570
        nBytes := nBytes + 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3571
        t := ByteArray uninitializedNew:nBytes.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3572
        t replaceFrom:1 to:nBytes-1 with:digitByteArray startingAt:1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3573
        t at:nBytes put:0.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3574
        digitByteArray := t.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3575
    ].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3576
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3577
%{
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3578
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3579
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3580
    if (__isByteArray(__digits)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3581
        int __nBytes = __intVal(nBytes);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3582
        unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3583
        unsigned INT __carry = 0, __newCarry,  __this;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3584
        int __idx;
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3585
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3586
#if defined(alpha64)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3587
        if (sizeof(unsigned INT) == 8) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3588
            while (__nBytes >= 8) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3589
                __this = ((unsigned INT *)__bp)[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3590
                __newCarry = (__this >> 63) /* & 1 */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3591
                ((unsigned INT *)__bp)[0] = (__this << 1) | __carry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3592
                __carry = __newCarry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3593
                __bp += 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3594
                __nBytes -= 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3595
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3596
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3597
#else
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3598
# if defined(__LSBFIRST) || defined(i386) /* XXX actually: LSB_FIRST */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3599
        if (sizeof(unsigned INT) == 4) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3600
            while (__nBytes >= 4) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3601
                __this = ((unsigned INT *)__bp)[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3602
                __newCarry = (__this >> 31) /* & 1 */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3603
                ((unsigned INT *)__bp)[0] = (__this << 1) | __carry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3604
                __carry = __newCarry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3605
                __bp += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3606
                __nBytes -= 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3607
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3608
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3609
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  3610
#endif
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3611
        while (__nBytes) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3612
            __this = __bp[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3613
            __newCarry = (__this >> 7) /* & 1 */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3614
            __bp[0] = (__this << 1) | __carry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3615
            __carry = __newCarry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3616
            __bp++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3617
            __nBytes--;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3618
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3619
        RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3620
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3621
%}.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3622
    self primitiveFailed
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3623
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3624
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3625
     100000 asLargeInteger mul2 
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3626
     10000000000000000000000000000 mul2 
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3627
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3628
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3629
    "Modified: 5.11.1996 / 16:37:32 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3630
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3631
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3632
mul256
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3633
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3634
       destructively multiply the receiver by 256."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3635
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3636
    |newDigits newSize|
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3637
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3638
    newSize := digitByteArray size + 1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3639
    newDigits := ByteArray uninitializedNew:newSize.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3640
"/    newDigits replaceFrom:2 with:digitByteArray startingAt:1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3641
    newDigits replaceBytesFrom:2 to:newSize with:digitByteArray startingAt:1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3642
    newDigits at:1 put:0.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3643
    digitByteArray := newDigits
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  3644
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3645
    "Modified: / 20.5.1999 / 09:16:42 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3646
!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3647
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3648
numberOfDigits:nDigits
2001
8c2b957f0cb3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
  3649
"/    digitByteArray := ByteArray uninitializedNew:nDigits.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3650
    digitByteArray := ByteArray new:nDigits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3651
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3652
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3653
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3654
setDigits:digits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3655
    digitByteArray := digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3656
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3657
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3658
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3659
sign:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3660
    sign := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3661
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3662
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3663
!LargeInteger methodsFor:'testing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3664
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3665
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3666
    "return true if the receiver is even"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3667
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3668
    ^ (digitByteArray at:1) even
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3669
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3670
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3671
negative
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3672
    "return true, if the receiver is < 0"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3673
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3674
    ^ (sign < 0)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3675
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3676
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3677
odd
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3678
    "return true if the receiver is odd"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3679
1983
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  3680
    ^ (digitByteArray at:1) odd
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  3681
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  3682
    "Modified: 18.11.1996 / 22:19:19 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3683
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3684
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3685
positive
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3686
    "return true, if the receiver is >= 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3687
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3688
    ^ (sign >= 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3689
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3690
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3691
sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3692
    "return the sign of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3693
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3694
    ^ sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3695
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3696
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3697
strictlyPositive
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3698
    "return true, if the receiver is > 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3699
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3700
    ^ (sign > 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3701
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3702
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  3703
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3704
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3705
version
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3706
    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.116 1999-06-04 08:36:28 cg Exp $'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3707
! !