LargeInteger.st
author ca
Fri, 26 Nov 1999 13:43:34 +0100
changeset 5020 eff43341e72c
parent 5014 fa22b711e749
child 5022 0ca9250856e7
permissions -rw-r--r--
added #digitBytes:MSB:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
345
claus
parents: 250
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
Integer subclass:#LargeInteger
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    14
	instanceVariableNames:'sign digitByteArray'
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    15
	classVariableNames:''
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    16
	poolDictionaries:''
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
    20
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
 COPYRIGHT (c) 1994 by Claus Gittinger
345
claus
parents: 250
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    36
documentation
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    37
"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    38
    This class provides arbitrary precision integers. These are represented as:
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    39
      sign (-1/0/+1) and, if sign ~~ 0
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    40
      a ByteArray of digits with 8 bits per element; 
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
      least significant 8 bits at index 1 ...
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    42
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    43
    The implementation is not completely tuned for high performance
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    44
    (more key-methods should be rewritten as primitives), although the
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    45
    common operations have been pretty tuned for some architectures.
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    46
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    47
    LargeIntegers are usually not created explicitely, but result from 
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    48
    SmallInteger arithmetic (overflowing the SmallInteger range).
357
claus
parents: 345
diff changeset
    49
    Also, results of LargeInteger operations are converted to back to 
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    50
    SmallIntegers, when possible (see #compressed).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    51
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    52
    In contrast to ST-80, there is only one class for LargeIntegers, keeping
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    53
    the sign as an instance variable (ST-80 has LargePositiveInteger and
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    54
    LargeNegativeInteger). This may change.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    55
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    56
    [author:]
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    57
        Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    58
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    59
    [see also:]
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    60
        Number
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    61
        Float Fraction FixedPoint 
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    62
        SmallInteger
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    63
"
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    64
!
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    65
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    66
testing
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    67
"
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    68
   test largeInt multiplication & division 
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    69
   (at least, test if they have not both errors which anull each other ;-)
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    70
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    71
   |last v|
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    72
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    73
   v := last := 1.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    74
   2 to:3000 do:[:i |
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    75
       i printCR.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    76
       v := v * i.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    77
       (v / i) ~= last ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
    78
	   self halt
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    79
       ].
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    80
       last := v.
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    81
   ]
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    82
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    83
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    84
   test addition, subtraction:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    85
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    86
   SmallInteger maxVal                -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    87
   SmallInteger maxVal + 1            -> 1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    88
   SmallInteger maxVal + 2            -> 1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    89
   (SmallInteger maxVal + 2) - 2      -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    90
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    91
   SmallInteger minVal                -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    92
   SmallInteger minVal - 1            -> -1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    93
   SmallInteger minVal - 2            -> -1073741826
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    94
   (SmallInteger minVal - 2) + 2      -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    95
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    96
   1234567890 + 10                    -> 1234567900
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    97
   1111111111 + 1111111111            -> 2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    98
   1111111111 - 1111111111            -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    99
   1111111111 - 2222222222            -> -1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   100
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   101
   1111111111 * 2                     -> 2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   102
   1111111111 * -2                    -> -2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   103
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   104
   1111111111 * 1111111111            -> 1234567900987654321
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   105
   1234567900987654321 // 1111111111  -> 1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   106
   1234567900987654321 \\ 1111111111  -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   107
   1234567900987654322 \\ 1111111111  -> 1
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   108
   1234567900987654421 \\ 1111111111  -> 100
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   109
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   110
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   111
   addition:
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   112
   (16rFFFFFFF0 + 1          ) hexPrintString -> 'FFFFFFF1'     
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   113
   (16rFFFFFFFF + 1          ) hexPrintString -> '100000000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   114
   (16rFFFFFFFF + 2          ) hexPrintString -> '100000001'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   115
   (16rFFFFFFFF + 16rFFFFFF  ) hexPrintString -> '100FFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   116
   (16rFFFFFFFF + 16rFFFFFFFF) hexPrintString -> '1FFFFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   117
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   118
   20 factorial         -> 2432902008176640000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   119
   20 factorial + 10000 -> 2432902008176650000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   120
   20 factorial               hexPrintString -> '21C3677C82B40000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   121
   (20 factorial + 16rFFFF)   hexPrintString -> '21C3677C82B4FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   122
   (20 factorial + 16rFFFFFF) hexPrintString -> '21C3677C83B3FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   123
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   124
   test comparison:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   125
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   126
   -1234567890 >  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   127
   -1234567890 >= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   128
   -1234567890 <  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   129
   -1234567890 <= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   130
   -1234567890 =  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   131
   -1234567890 ~= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   132
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   133
   -1234567890 >  -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   134
   -1234567890 >= -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   135
   -1234567890 <  -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   136
   -1234567890 <= -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   137
   -1234567890 =  -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   138
   -1234567890 ~= -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   139
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   140
   -1234567891 >  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   141
   -1234567891 >= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   142
   -1234567891 <  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   143
   -1234567891 <= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   144
   -1234567891 =  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   145
   -1234567891 ~= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   146
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   147
    1234567890 >  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   148
    1234567890 >= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   149
    1234567890 <  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   150
    1234567890 <= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   151
    1234567890 =  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   152
    1234567890 ~= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   153
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   154
   -1234567890 >  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   155
   -1234567890 >= 1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   156
   -1234567890 <  1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   157
   -1234567890 <= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   158
   -1234567890 =  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   159
   -1234567890 ~= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   160
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   161
    1234567890 >  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   162
    1234567890 >= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   163
    1234567890 <  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   164
    1234567890 <= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   165
    1234567890 =  1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   166
    1234567890 ~= 1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   167
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   168
   -1234567890 >  -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   169
   -1234567890 >= -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   170
   -1234567890 <  -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   171
   -1234567890 <= -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   172
   -1234567890 =  -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   173
   -1234567890 ~= -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   174
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   175
   -1234567890 >  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   176
   -1234567890 >= 10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   177
   -1234567890 <  10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   178
   -1234567890 <= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   179
   -1234567890 =  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   180
   -1234567890 ~= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   181
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   182
   -10 >  -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   183
   -10 >= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   184
   -10 <  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   185
   -10 <= -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   186
   -10 =  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   187
   -10 ~= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   188
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   189
    10 >  -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   190
    10 >= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   191
    10 <  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   192
    10 <= -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   193
    10 =  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   194
    10 ~= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   195
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   196
    1234567890 >  -10                 true  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   197
    1234567890 >= -10                 true  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   198
    1234567890 <  -10                 false  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   199
    1234567890 <= -10                 false  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   200
    1234567890 =  -10                 false  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   201
    1234567890 ~= -10                 true  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   202
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   203
    1234567890 >  10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   204
    1234567890 >= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   205
    1234567890 <  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   206
    1234567890 <= 10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   207
    1234567890 =  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   208
    1234567890 ~= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   209
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   210
   -10 >   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   211
   -10 >=  1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   212
   -10 <   1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   213
   -10 <=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   214
   -10 =   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   215
   -10 ~=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   216
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   217
    10 >   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   218
    10 >=  1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   219
    10 <   1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   220
    10 <=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   221
    10 =   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   222
    10 ~=  1234567890                 true
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
   223
"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   224
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   225
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   226
!LargeInteger class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   227
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   228
digitBytes:aByteArrayOfDigits
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   229
    "create and return a new LargeInteger with digits (lsb-first)
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   230
     from the argument, aByteArray.
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   231
     Experimental interface - May change/be removed without notice."
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   232
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   233
    ^ self basicNew setDigits:aByteArrayOfDigits
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   234
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   235
    "
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   236
     LargeInteger digitBytes:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]
4806
1b48e7420cfe comment
Claus Gittinger <cg@exept.de>
parents: 4794
diff changeset
   237
     (LargeInteger digitBytes:#[16r12 16r34 16r56 16r78 16r90]) hexPrintString
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   238
    "
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   239
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   240
    "Modified: / 8.5.1998 / 21:40:41 / cg"
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   241
!
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   242
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   243
digitBytes:aByteArrayOfDigits MSB:msb
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   244
    "create and return a new LargeInteger with digits (which may be in either msb/lsb order)
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   245
     from the argument, aByteArray."
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   246
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   247
    msb == false ifTrue:[
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   248
        ^ self basicNew setDigits:aByteArrayOfDigits
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   249
    ].
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   250
    ^ self basicNew setDigits:(aByteArrayOfDigits copy reverse)
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   251
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   252
    "
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   253
     (LargeInteger digitBytes:#[16r10 16r20 16r30 16r00] MSB:false) hexPrintString  
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   254
     (LargeInteger digitBytes:#[16r10 16r20 16r30 16r00] MSB:true) hexPrintString   
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   255
    "
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   256
!
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   257
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   258
new
4299
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   259
    "catch creation message.
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   260
     LargeIntegers are only created by system code, which 
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   261
     uses basicNew and cares for correct initialization."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   262
a27a279701f8 Initial revision
claus
parents:
diff changeset
   263
    self error:'LargeIntegers cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   265
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   266
new:numberOfDigits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   267
    "catch creation message"
2
claus
parents: 1
diff changeset
   268
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   269
    self error:'LargeIntegers cannot be created with new'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   271
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   272
value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   273
    "create and return a new LargeInteger with value taken from
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   274
     the argument, aSmallInteger.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   275
     Notice: 
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   276
	this should be only used internally, since such small
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   277
	largeIntegers do not normally occur in the system.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   278
	(They are used by myself)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   279
     May change/be removed without notice."
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   280
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   281
    ^ self basicNew value:aSmallInteger
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
    "LargeInteger value:3689"
3438
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   284
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   285
    "Modified: / 8.5.1998 / 21:40:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   286
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   288
!LargeInteger class methodsFor:'queries'!
701
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
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   291
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   292
     Here, true is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   293
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   294
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   295
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   296
    "Modified: 23.4.1996 / 15:59:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   297
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   298
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   299
!LargeInteger methodsFor:'arithmetic'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   300
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   304
    |otherSign numberClass|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   306
    (sign == 0) ifTrue:[^ 0].  "cannot happen if correctly normalized"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   309
     this is the common case, multiplying with SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   310
     Use a special method for this case ...
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   311
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   312
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
	^ self productFromInteger:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   314
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   315
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   316
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
     if the argument is not a largeInteger, coerce
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   318
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   319
    (numberClass == self class) ifFalse:[
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   320
	^ self retry:#* coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   321
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
    (sign == otherSign) ifTrue:[^ self absMul:aNumber].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   325
    (otherSign == 0) ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   326
    ^ (self absMul:aNumber) sign:-1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   327
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   328
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   329
+ aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   330
    "return the sum of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   331
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   332
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   333
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   334
    (sign == 0) ifTrue:[^ aNumber].  "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   335
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   336
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   337
     this is the common case, adding a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   338
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   339
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   340
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   341
	^ self sumFromInteger:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   342
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   343
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   344
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   345
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   346
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   347
    (numberClass == self class) ifFalse:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   348
	^ self retry:#+ coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   349
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   350
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   351
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   352
    (sign > 0) ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   353
	"I am positive"
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   354
	(otherSign > 0) ifTrue:[^ self absPlus:aNumber sign:1].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   355
	(otherSign < 0) ifTrue:[^ self absMinus:aNumber sign:1].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   356
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   357
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   358
    "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
   359
    (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
   360
    (otherSign < 0) ifTrue:[^ self absPlus:aNumber sign:-1].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   361
    ^ self
357
claus
parents: 345
diff changeset
   362
claus
parents: 345
diff changeset
   363
    "
claus
parents: 345
diff changeset
   364
     SmallInteger maxVal 
claus
parents: 345
diff changeset
   365
     SmallInteger maxVal + 1  
claus
parents: 345
diff changeset
   366
     SmallInteger maxVal + 2 
claus
parents: 345
diff changeset
   367
     SmallInteger minVal    
claus
parents: 345
diff changeset
   368
     SmallInteger minVal - 1
claus
parents: 345
diff changeset
   369
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   370
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   371
    "Modified: / 9.1.1998 / 13:26:28 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   372
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   373
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   374
- aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   375
    "return the difference of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   376
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   377
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   378
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   379
    (sign == 0) ifTrue:[^ aNumber negated].     "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   380
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   381
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   382
     this is the common case, subtracting a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   383
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   384
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   385
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   386
        sign > 0 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   387
            aNumber > 0 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   388
                ^ self absFastMinus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   389
            ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   390
            ^ self absFastPlus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   391
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   392
        aNumber > 0 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   393
            ^ self absFastPlus:aNumber sign:-1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   394
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   395
        ^ self absFastMinus:aNumber sign:-1
92
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
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   399
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   400
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   401
    (numberClass == self class) ifFalse:[
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   402
        ^ self retry:#- coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   403
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   404
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   405
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   406
    (sign > 0) ifTrue:[
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   407
        "I am positive"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   408
        (otherSign > 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   409
            "+large - +large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   410
            ^ self absMinus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   411
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   412
        (otherSign < 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   413
            "+large - -large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   414
            ^ self absPlus:aNumber sign:1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   415
        ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   416
        "should not happen"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   417
        ^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   418
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   419
    "I am negative"
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   420
    (otherSign > 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   421
        "-large - +large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   422
        ^ self absPlus:aNumber sign:-1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   423
    ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   424
    (otherSign < 0) ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   425
        "-large - -large"
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   426
        ^ self absMinus:aNumber sign:-1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   427
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   428
    ^ self
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   429
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   430
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   431
     12345678901234567890 - 0     
357
claus
parents: 345
diff changeset
   432
     12345678901234567890 - 1      
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   433
     12345678901234567890 - -1    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   434
     -12345678901234567890 - 1     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   435
     -12345678901234567890 - -1    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   436
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   437
     12345678901234567890 - 12345678901234567880     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   438
     12345678901234567890 - 12345000000000000000     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   439
     12345678901234567890 - -87654321098765432110    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   440
     -12345678901234567890 - 87654321098765432110    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   441
     -12345678901234567890 - -12345678901234567880   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   442
     -12345678901234567890 - -12345678901234567980   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   443
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   444
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   445
    "Modified: 20.10.1996 / 18:42:16 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   446
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   447
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   448
/ aNumber
1065
77b25fb9f9d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   449
    "return the quotient of the receiver and the argument, aNumber"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   450
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   451
    aNumber isInteger ifTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   452
	^ Fraction numerator:self
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   453
		  denominator:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   454
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   455
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   456
    "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
   457
    ^ (self asFloat / aNumber asFloat)
2793
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   458
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   459
    "Modified: 28.7.1997 / 19:07:55 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   460
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   461
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   462
// aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   463
    "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
   464
     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
   465
     if the operands signs differ."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   466
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   467
    |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
   468
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   469
    cls := aNumber class.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   470
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   471
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   472
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   473
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   474
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   475
    (cls == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   476
	abs := aNumber.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   477
	abs := abs abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   478
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   479
	    divMod := self absFastDivMod:abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   480
	] ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   481
	    n := abs asLargeInteger.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   482
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   483
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   484
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   485
	 if the argument is not a largeInteger, coerce
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   486
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   487
	(cls == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   488
	    ^ self retry:#// coercing:aNumber
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   489
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   490
	n := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   491
    ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   492
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   493
    divMod isNil ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   494
	divMod := self absDivMod:n.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   495
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   496
    quo := divMod at:1.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   497
    (sign == aNumber sign) ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   498
	"/ adjust for truncation if negative and there is a remainder ...
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   499
	quo := quo sign:-1.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   500
	(divMod at:2) == 0 ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   501
	    ^ quo - 1
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   502
	].
3984
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
    ^ quo
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   505
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   506
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   507
     (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
   508
     (-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
   509
     (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
   510
     (-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
   511
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   512
     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
   513
     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
   514
     16rfffffffff // 16r001fffff  =  32768 ifFalse:[self halt].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   515
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   516
     900 quo: 400   
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   517
     -900 quo: 400                   
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   518
     900 quo: -400                   
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   519
     -900 quo: -400 
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   520
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   521
     9000000000 quo: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   522
     -9000000000 quo: 4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   523
     9000000000 quo: -4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   524
     -9000000000 quo: -4000000000 
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   525
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   526
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   527
    "Modified: / 5.11.1996 / 16:39:36 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   528
    "Modified: / 27.4.1999 / 19:50:26 / stefan"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   529
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   530
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   531
\\ aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   532
    "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
   533
     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
   534
     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
   535
     Compare with #rem:"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   536
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   537
    |abs rem negativeDivisor|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   538
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   539
    aNumber negative ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   540
	negativeDivisor := true.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   541
	abs := aNumber negated.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   542
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   543
	negativeDivisor := false.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   544
	abs := aNumber.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   545
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   546
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   547
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   548
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   549
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   550
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   551
    (aNumber class == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   552
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   553
	    rem := (self absFastDivMod:abs) at:2.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   554
	] ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   555
	    rem := self absMod:abs asLargeInteger
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   556
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   557
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   558
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   559
	 if the argument is not a largeInteger, coerce
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   560
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   561
	(aNumber class == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   562
	    ^ self retry:#\\ coercing:aNumber
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   563
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   564
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   565
	rem := self absMod:abs.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   566
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   567
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   568
    rem = 0 ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   569
	negativeDivisor ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   570
	    rem := rem sign:-1
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   571
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   572
	(self negative ~~ negativeDivisor) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   573
	    "different sign, so remainder would have been negative.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   574
	     rem has been rounded toward zero, this code will simulate
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   575
	     rounding to negative infinity."
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   576
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   577
	    rem := aNumber - rem.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   578
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   579
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   580
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   581
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   582
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   583
     (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
   584
     (-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
   585
     (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
   586
     (-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
   587
     (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
   588
     (-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
   589
     (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
   590
     (-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
   591
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   592
     9000000000 \\ 7      
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   593
     -9000000000 \\ 7     
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   594
     9000000000 \\ -7     
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   595
     -9000000000 \\ -7    
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   596
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   597
     900 rem: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   598
     -900 rem: 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   599
     900 rem: -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   600
     -900 rem: -400               
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   601
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   602
     9000000000 rem: 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   603
     -9000000000 rem: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   604
     9000000000 rem: -4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   605
     -9000000000 rem: -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   606
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   607
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   608
    "Modified: / 5.11.1996 / 17:10:10 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   609
    "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
   610
!
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   611
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   612
abs
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   613
    "return my absolute value. redefined for speed."
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   614
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   615
    sign >= 0 ifTrue:[^ self].
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   616
    ^ self negated
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   617
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   618
    "Created: / 26.10.1999 / 21:28:06 / stefan"
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   619
!
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   620
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   621
divMod:aNumber
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   622
    "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
   623
     self \\ aNumber.
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   624
     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
   625
     argument."
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   626
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   627
    |cls n|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   628
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   629
    cls := aNumber class.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   630
    (cls == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   631
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   632
	 this is the common case, dividing by a SmallInteger.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   633
	 Use a special method for this case ...
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   634
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   635
	(aNumber between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   636
	    ^ self absFastDivMod:aNumber abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   637
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   638
	n := aNumber asLargeInteger.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   639
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   640
	(cls == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   641
	    ^ super divMod:aNumber            
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   642
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   643
	n := aNumber.
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   644
    ].
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   645
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   646
    ^ self absDivMod:n abs
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   647
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   648
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   649
     9000000000 // 4000000000   => 2
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   650
     9000000000 \\ 4000000000   => 1000000000 
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   651
     9000000000 divMod: 4000000000   => #(2 1000000000)
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   652
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   653
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   654
    "Created: / 29.10.1996 / 21:22:05 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   655
    "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
   656
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   657
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   658
negated
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   659
    "return an integer with value negated from the receivers value."
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   660
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   661
    |newNumber sz|
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   662
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   663
    (sign == 0) ifTrue:[^ 0].
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   664
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   665
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   666
     special case for SmallInteger minVal
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   667
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   668
    sign == 1 ifTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   669
	sz := digitByteArray size.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   670
%{
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   671
	int idx;
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   672
	unsigned char *bp;
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   673
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   674
	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
   675
	idx = __intVal(sz);
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   676
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   677
	while ((idx > 1) && (bp[idx-1] == 0)) idx--;
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   678
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   679
	if (idx == sizeof(INT)) {
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   680
#if defined(alpha64)
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   681
	    if ( ((unsigned INT *)bp)[0] == 0x4000000000000000L)
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   682
#else
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   683
# if defined(i386) /* actually: LSBFIRST */
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   684
	    if ( ((unsigned INT *)bp)[0] == 0x40000000)
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   685
# else
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   686
	    /*
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   687
	     * generic code
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   688
	     */
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   689
	    if ((bp[idx-1] == 0x40)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   690
	     && (bp[idx-2] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   691
	     && (bp[idx-3] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   692
	     && (bp[idx-4] == 0)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   693
#  ifdef alpha64
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   694
	     && (bp[idx-5] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   695
	     && (bp[idx-6] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   696
	     && (bp[idx-7] == 0)
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
   697
	     && (bp[idx-8] == 0)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   698
#  endif
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   699
	    ) 
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   700
# endif
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   701
#endif
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   702
	    {
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   703
		RETURN (__MKSMALLINT(_MIN_INT));
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   704
	    }
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   705
	}
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   706
%}.
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   707
"/      sz == 4 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   708
"/        (digitByteArray at:1) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   709
"/          (digitByteArray at:2) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   710
"/            (digitByteArray at:3) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   711
"/              (digitByteArray at:4) == 16r40 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   712
"/                ^ SmallInteger minVal
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   713
"/              ].
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   714
"/            ]
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   715
"/          ]
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   716
"/        ]
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   717
"/      ]
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   718
    ].
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   719
    newNumber := self shallowCopy.
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   720
    newNumber sign:(sign negated).
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   721
    ^ newNumber
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   722
!
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   723
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   724
quo:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   725
    "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
   726
     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
   727
     truncates toward negative infinity).
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   728
     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
   729
     different from the args sign"
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   730
2521
43b9d4fafb35 removed unused locals
Claus Gittinger <cg@exept.de>
parents: 2495
diff changeset
   731
    |otherSign quo abs "{ Class: SmallInteger }" |
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   732
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   733
    otherSign := aNumber sign.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   734
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   735
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   736
     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
   737
     Use a special method for this case ...
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   738
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   739
    (aNumber class == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   740
	abs := aNumber.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   741
	abs := abs abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   742
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   743
	    quo := (self absFastDivMod:abs) at:1.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   744
	    (sign == otherSign) ifTrue:[^ quo].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   745
	    ^ quo sign:-1
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   746
	]
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   747
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   748
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   749
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   750
     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
   751
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   752
    (aNumber class == self class) ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   753
	^ self retry:#quo: coercing:aNumber
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   754
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   755
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   756
    sign < 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   757
	(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
   758
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   759
	(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
   760
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   761
    ^ ((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
   762
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   763
    "
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   764
     900 // 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   765
     -900 // 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   766
     900 // -400 
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   767
     -900 // -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   768
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   769
     9000000000 // 4000000000     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   770
     -9000000000 // 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   771
     9000000000 // -4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   772
     -9000000000 // -4000000000   
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   773
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   774
     900 quo: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   775
     -900 quo: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   776
     900 quo: -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   777
     -900 quo: -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   778
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   779
     9000000000 quo: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   780
     -9000000000 quo: 4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   781
     9000000000 quo: -4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   782
     -9000000000 quo: -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   783
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   784
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   785
    "Modified: / 5.11.1996 / 14:14:17 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   786
    "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
   787
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   788
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   789
rem:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   790
    "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
   791
     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
   792
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   793
    |rem abs "{ Class: SmallInteger }" |
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   794
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   795
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   796
     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
   797
     Use special code for this case ...
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   798
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   799
    (aNumber class == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   800
	abs := aNumber.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   801
	abs := abs abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   802
	(abs between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   803
	    rem := (self absFastDivMod:abs) at:2.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   804
	] ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   805
	    rem := self absMod:abs asLargeInteger
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   806
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   807
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   808
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   809
	 if the argument is not a largeInteger, coerce
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   810
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   811
	(aNumber class == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   812
	    ^ self retry:#rem coercing:aNumber
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   813
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   814
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   815
	rem := self absMod:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   816
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   817
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   818
    sign < 0 ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   819
	^ rem sign:-1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   820
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   821
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   822
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   823
    "
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   824
     900 \\ 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   825
     -900 \\ 400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   826
     900 \\ -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   827
     -900 \\ -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   828
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   829
     9000000000 \\ 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   830
     -9000000000 \\ 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   831
     9000000000 \\ -4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   832
     -9000000000 \\ -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   833
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   834
     900 rem: 400     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   835
     -900 rem: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   836
     900 rem: -400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   837
     -900 rem: -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   838
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   839
     9000000000 rem: 4000000000     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   840
     -9000000000 rem: 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   841
     9000000000 rem: -4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   842
     -9000000000 rem: -4000000000   
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   843
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   844
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   845
    "Modified: / 5.11.1996 / 14:02:59 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   846
    "Modified: / 29.4.1999 / 11:26:51 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   847
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   848
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   849
!LargeInteger methodsFor:'bit operators'!
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   850
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   851
bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   852
    "return the bitwise-and of the receiver and the argument, anInteger"
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   853
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   854
%{  /* NOCONTEXT */
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   855
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   856
    if (__isSmallInteger(anInteger)) {
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   857
        INT v2 = __intVal(anInteger);
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   858
        INT v1;
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   859
#if defined(__LSBFIRST) || defined(i386)
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   860
        v1 = *(INT *)(__stringVal(__INST(digitByteArray)));
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   861
#else
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   862
        unsigned char *digits = (unsigned char *)(__stringVal(__INST(digitByteArray)));
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   863
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   864
        v1 = digits[0] & 0xFF;
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   865
        v1 = v1 | ((digits[1] & 0xFF)<<8);
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   866
        v1 = v1 | ((digits[2] & 0xFF)<<16);
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   867
        v1 = v1 | ((digits[3] & 0xFF)<<24);
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   868
#endif
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   869
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   870
        RETURN ( __MKSMALLINT(v1 & v2) );
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   871
    }
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   872
%}.
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   873
    ^ super bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   874
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   875
    "
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   876
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFF) 
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   877
    "
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   878
!
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   879
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   880
bitXor:anInteger
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   881
    "return the bitwise-or of the receiver and the argument, anInteger.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   882
     Here, a specially tuned version for largeInteger arguments 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   883
     (to speed up some cryptographic code)"
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   884
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   885
    |n "{ Class: SmallInteger }"
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   886
     len1 len2 result byte newBytes|
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   887
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   888
    anInteger class ~~ LargeInteger ifTrue:[^ super bitXor:anInteger].
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   889
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   890
    (len1 := anInteger digitLength) > (len2 := self digitLength) ifTrue:[
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   891
        newBytes := anInteger digits copy.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   892
        newBytes bitXorBytesFrom:1 to:len2 with:digitByteArray startingAt:1 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   893
    ] ifFalse:[
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   894
        newBytes := digitByteArray copy.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   895
        newBytes bitXorBytesFrom:1 to:len1 with:anInteger digits startingAt:1 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   896
    ].
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   897
    ^ (LargeInteger digitBytes:newBytes) compressed
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   898
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   899
    "
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   900
     (16r112233445566778899 bitXor:16rFF                ) printStringRadix:16 '112233445566778866' 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   901
     (16r112233445566778899 bitXor:16rFFFFFFFFFFFFFFFF00) printStringRadix:16 'EEDDCCBBAA99887799'
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   902
     (16r112233445566778899 bitXor:16rFF0000000000000000) printStringRadix:16 'EE2233445566778899'
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   903
     (16r112233445566778899 bitXor:16r112233445566778800) printStringRadix:16 '99' 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   904
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   905
     |bigNum1 bigNum2|
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   906
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   907
     bigNum1 := 2 raisedToInteger:512.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   908
     bigNum2 := 2 raisedToInteger:510.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   909
     Time millisecondsToRun:[
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   910
        1000000 timesRepeat:[
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   911
           bigNum1 bitXor:bigNum2.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   912
        ]
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   913
     ]      
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   914
    "
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   915
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   916
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   917
!
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   918
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   919
lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   920
    "return the bitIndex of the lowest bit set. The returned bitIndex
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   921
     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
   922
     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
   923
     Redefined here for more performance of the gcd: algorithm, which
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   924
     is used when big fractions are reduced."
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   925
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   926
    |sz "{ Class: SmallInteger }"
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   927
     byte|
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   928
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   929
    sz := digitByteArray size.
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   930
    1 to:sz do:[:digitIndex |
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   931
	(byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   932
	    ^ (digitIndex-1)*8 + byte lowBit
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   933
	]
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   934
    ].
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   935
    ^ -1
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   936
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   937
    "
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   938
     (1 bitShift:30) lowBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   939
     (1 bitShift:30) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   940
     (1 bitShift:31) lowBit   
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   941
     (1 bitShift:31) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   942
     (1 bitShift:32) lowBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   943
     (1 bitShift:32) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   944
     (1 bitShift:33) lowBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   945
     (1 bitShift:33) highBit 
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   946
     (1 bitShift:64) lowBit 
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   947
     (1 bitShift:64) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   948
     (1 bitShift:1000) lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   949
     (1 bitShift:1000) highBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   950
     ((1 bitShift:64)-1) lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   951
     ((1 bitShift:64)-1) highBit  
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   952
    "
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   953
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   954
    "Modified: 14.8.1997 / 11:55:34 / cg"
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   955
! !
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   956
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   957
!LargeInteger methodsFor:'byte access'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   958
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   959
digitAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   960
    "return 8 bits of value, starting at byte index"
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
    index > digitByteArray size ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   963
    ^ digitByteArray at:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   964
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   965
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   966
digitAt:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   967
    "set the 8 bits, index is a byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   968
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   969
    digitByteArray at:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   970
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   971
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   972
digitByteAt:index
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   973
    "return 8 bits of my signed value, starting at byte index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   974
     For positive receivers, this is the same as #digitAt:;
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   975
     for negative ones, the actual bit representation is returned."
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   976
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   977
    |t digits|
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   978
    sign < 0 ifFalse:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   979
        index > digitByteArray size ifTrue:[
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   980
            ^ 0
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   981
        ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   982
        ^ digitByteArray at:index.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   983
    ].
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   984
    "/ negative int - do 2's complement here
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   985
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   986
    t := self bitInvert + 1.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   987
    t sign:1.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   988
    digits := t digitBytes.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   989
    index > digits size ifTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
   990
        ^ 16rFF
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   991
    ].
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   992
    ^ digits at:index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   993
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   994
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   995
     16r11111111111111111111 negated digitByteAt:1
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   996
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   997
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   998
    "Created: / 25.10.1998 / 14:12:21 / cg"
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
   999
!
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1000
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1001
digitBytes
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1002
    "return a byteArray filled with the receivers bits
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1003
     (8 bits of the absolute value per element).
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1004
     Least significant byte is first!!"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1005
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1006
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1007
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1008
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1009
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1010
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1011
digitBytesMSB:msbFlag
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1012
    "return a byteArray filled with the receivers bits
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1013
     (8 bits of the absolute value per element),
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1014
     if msbflag = true, most significant byte is first,
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1015
     otherwise least significant byte is first"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1016
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1017
    msbFlag ifTrue:[
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1018
        ^ digitByteArray copyReverse.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1019
    ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1020
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1021
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1022
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1023
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1024
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1025
digitLength
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1026
    "return the number bytes used by this Integer.
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1027
     For negative receivers, the digitLength of its absolute value
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1028
     is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1029
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1030
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1031
     check if there is a 0-byte ...
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1032
     this allows to ask unnormalized LargeIntegers 
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1033
     for their digitLength
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1034
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1035
    |l "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1036
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1037
    l := digitByteArray size.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1038
    [l ~~ 0 and:[(digitByteArray at:l) == 0]] whileTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1039
	l := l - 1.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1040
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1041
    ^ l
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1042
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1043
    "Modified: 31.7.1997 / 13:18:28 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1044
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1045
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1046
digits
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1047
    "obsolete,use #digitBytes"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1048
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1049
    ^ digitByteArray
4151
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
  1050
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
  1051
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1052
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1053
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1054
!LargeInteger methodsFor:'coercing & converting'!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1055
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1056
asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1057
    "return a Float with same value as myself.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1058
     Since floats have a limited precision, you usually loose bits when
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1059
     doing this."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1060
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1061
    |newFloat|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1062
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1063
    newFloat := 0.0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1064
    (sign == 0) ifFalse:[
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1065
        digitByteArray reverseDo:[:aDigit |
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1066
            newFloat := (newFloat * 256.0) + aDigit asFloat
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1067
        ].
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1068
        (sign < 0) ifTrue:[
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1069
            newFloat := newFloat negated
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1070
        ]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1071
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1072
    ^ newFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1073
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1074
    "
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1075
     1234567890 asFloat                     
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1076
     1234567890 asFloat asInteger                    
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1077
     12345678901234567890 asFloat           
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1078
     12345678901234567890 asFloat asInteger   
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1079
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1080
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1081
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1082
asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1083
    "return a LargeInteger with same value as myself - thats me"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1084
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1085
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1086
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1087
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1088
asSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1089
    "return a SmallInteger with same value as myself - 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1090
     the result is invalid if the receivers value cannot 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1091
     be represented as a SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1092
     Q: should we raise an exception if this happens ?"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1093
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1094
    |value|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1095
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1096
    value := 0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1097
    (sign == 0) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1098
	digitByteArray reverseDo:[:aDigit |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1099
	    value := (value times:256) + aDigit 
345
claus
parents: 250
diff changeset
  1100
	].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1101
	(sign < 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1102
	    value := value negated
345
claus
parents: 250
diff changeset
  1103
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1104
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1105
    ^ value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1106
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1107
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1108
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1109
    "return the argument as a LargeInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1110
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1111
    ^ aNumber asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1112
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1113
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1114
compressed
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1115
    "if the receiver can be represented as a SmallInteger, return
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1116
     a SmallInteger with my value; 
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1117
     otherwise remove leading zero bytes in the digitByte array
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1118
     and return the receiver"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1119
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1120
    |index "{ Class: SmallInteger }" 
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1121
     val   "{ Class: SmallInteger }" 
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1122
     index0
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1123
    |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1124
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1125
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1126
    OBJ t;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1127
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1128
    if (__INST(sign) == __MKSMALLINT(0)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1129
        RETURN (__MKSMALLINT(0));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1130
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1131
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1132
    t = __INST(digitByteArray);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1133
    if (__isByteArray(t)) {
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1134
        unsigned char *__digitBytes = __ByteArrayInstPtr(t)->ba_element;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1135
        int _idx, _idx0;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1136
        INT _val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1137
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1138
        _idx = _idx0 = __byteArraySize(t);
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1139
        while ((_idx > 0) && (__digitBytes[_idx - 1] == 0)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1140
            _idx--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1141
        }
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
  1142
#ifdef alpha64
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1143
        switch (_idx) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1144
            case 8:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1145
                _val = __digitBytes[7];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1146
                if (_val <= 0x40) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1147
                    _val = (_val<<8);
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1148
                    _val = (_val + __digitBytes[6]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1149
                    _val = (_val + __digitBytes[5]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1150
                    _val = (_val + __digitBytes[4]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1151
                    _val = (_val + __digitBytes[3]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1152
                    _val = (_val + __digitBytes[2]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1153
                    _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1154
                    _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1155
                    if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1156
                        _val = -_val;
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1157
                    if (__ISVALIDINTEGER(_val)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1158
                        RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1159
                    }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1160
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1161
                break;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1162
            case 7:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1163
                _val = (__digitBytes[6]<<8);
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1164
                _val = (_val + __digitBytes[5]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1165
                _val = (_val + __digitBytes[4]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1166
                _val = (_val + __digitBytes[3]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1167
                _val = (_val + __digitBytes[2]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1168
                _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1169
                _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1170
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1171
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1172
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1173
            case 6:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1174
                _val = (__digitBytes[5]<<8);
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1175
                _val = (_val + __digitBytes[4]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1176
                _val = (_val + __digitBytes[3]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1177
                _val = (_val + __digitBytes[2]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1178
                _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1179
                _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1180
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1181
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1182
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1183
            case 5:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1184
                _val = (__digitBytes[4]<<8);
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1185
                _val = (_val + __digitBytes[3]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1186
                _val = (_val + __digitBytes[2]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1187
                _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1188
                _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1189
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1190
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1191
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1192
            case 4:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1193
                _val = (__digitBytes[3]<<8);
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1194
                _val = (_val + __digitBytes[2]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1195
                _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1196
                _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1197
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1198
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1199
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1200
            case 3:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1201
                _val = (__digitBytes[2]<<8);
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1202
                _val = (_val + __digitBytes[1]) << 8;
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1203
                _val += __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1204
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1205
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1206
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1207
            case 2:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1208
                _val = (__digitBytes[1]<<8) + __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1209
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1210
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1211
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1212
            case 1:
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1213
                _val = __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1214
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1215
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1216
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1217
            case 0:
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1218
                RETURN (__MKSMALLINT(0));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1219
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1220
        }
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1221
#else
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1222
        if (_idx <= 4) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1223
            if (_idx <= 2) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1224
                if (_idx == 0) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1225
                    RETURN (__MKSMALLINT(0));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1226
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1227
                if (_idx == 1) {
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1228
                    _val = __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1229
                    if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1230
                        _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1231
                    RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1232
                }
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1233
                _val = (__digitBytes[1]<<8) + __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1234
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1235
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1236
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1237
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1238
            if (_idx == 3) {
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1239
                _val = (((__digitBytes[2]<<8) + __digitBytes[1])<<8) + __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1240
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1241
                    _val = -_val;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1242
                RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1243
            }
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1244
            _val = __digitBytes[3];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1245
            if (_val <= 0x40) {
4831
98113bc11cdd Fix C name conflict (which came from prev change).
Claus Gittinger <cg@exept.de>
parents: 4828
diff changeset
  1246
                _val = (((((_val<<8) + __digitBytes[2])<<8) + __digitBytes[1])<<8) + __digitBytes[0];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1247
                if (__INST(sign) == __MKSMALLINT(-1))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1248
                    _val = -_val;
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1249
                if (__ISVALIDINTEGER(_val)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1250
                    RETURN (__MKSMALLINT(_val));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1251
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1252
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1253
        }
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1254
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1255
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1256
        if (_idx == _idx0) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1257
            RETURN (self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1258
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1259
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1260
        /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1261
         * must copy & cut off some bytes
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1262
         */
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
            OBJ newDigits;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1265
            OBJ oldDigits;
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
             * careful - there is no context here to protect
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1269
             * the receiver ...
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1270
             */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1271
            __PROTECT__(self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1272
            __PROTECT__(__INST(digitByteArray));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1273
            newDigits = __BYTEARRAY_UNINITIALIZED_NEW_INT(_idx);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1274
            __UNPROTECT__(oldDigits);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1275
            __UNPROTECT__(self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1276
            if (newDigits) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1277
                bcopy(__ByteArrayInstPtr(oldDigits)->ba_element,
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1278
                      __ByteArrayInstPtr(newDigits)->ba_element,
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1279
                      _idx);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1280
                __INST(digitByteArray) = newDigits; __STORE(self, newDigits);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1281
                RETURN (self);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1282
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1283
            /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1284
             * allocation failed ...
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1285
             * ... fall through to trigger the error
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1286
             */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1287
        }
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1288
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1289
%}.
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1290
    index0 := index := digitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1291
    [(index > 0) and:[(digitByteArray at:index) == 0]] whileTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1292
        index := index - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1293
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1294
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1295
    (index ~~ index0) ifTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1296
        digitByteArray := digitByteArray copyFrom:1 to:index
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1297
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1298
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1299
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1300
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1301
value:aSmallInteger
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1302
    "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
  1303
     This method will fail, if the argument is not a smallInteger.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1304
     This should only be used internally, 
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1305
     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
  1306
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1307
    |absValue 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1308
     b1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1309
     b2 "{ Class: SmallInteger }"
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1310
     b3 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1311
     b4 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1312
     b5 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1313
     b6 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1314
     b7 "{ Class: SmallInteger }"|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1315
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1316
    "
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1317
     could have simply created a 4-byte largeinteger and normalize it. 
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1318
     The code below does the normalize right away, avoiding the
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1319
     overhead of producing any intermediate byte-arrays (and the scanning)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1320
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1321
    (aSmallInteger == 0) ifTrue: [
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1322
        digitByteArray := ByteArray with:0.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1323
        sign := 0.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1324
        ^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1325
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1326
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1327
    (aSmallInteger < 0) ifTrue: [
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1328
        sign := -1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1329
        absValue := aSmallInteger negated
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1330
    ] ifFalse: [
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1331
        sign := 1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1332
        absValue := aSmallInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1333
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1334
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1335
    b1 := absValue bitAnd:16rFF.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1336
    absValue := absValue bitShift:-8.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1337
    absValue == 0 ifTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1338
        digitByteArray := ByteArray with:b1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1339
    ] ifFalse:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1340
        b2 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1341
        absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1342
        absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1343
            digitByteArray := ByteArray with:b1 with:b2
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1344
        ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1345
            b3 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1346
            absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1347
            absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1348
                digitByteArray := ByteArray with:b1 with:b2 with:b3
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1349
            ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1350
                b4 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1351
                absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1352
                absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1353
                    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1354
                ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1355
                    b5 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1356
                    absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1357
                    absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1358
                        digitByteArray := ByteArray new:5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1359
                        digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1360
                        digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1361
                        digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1362
                        digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1363
                        digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1364
                    ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1365
                        b6 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1366
                        absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1367
                        absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1368
                            digitByteArray := ByteArray new:6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1369
                            digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1370
                            digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1371
                            digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1372
                            digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1373
                            digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1374
                            digitByteArray at:6 put:b6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1375
                        ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1376
                            b7 := absValue bitAnd:16rFF.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1377
                            absValue := absValue bitShift:-8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1378
                            absValue == 0 ifTrue:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1379
                                digitByteArray := ByteArray new:7.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1380
                                digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1381
                                digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1382
                                digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1383
                                digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1384
                                digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1385
                                digitByteArray at:6 put:b6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1386
                                digitByteArray at:7 put:b7.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1387
                            ] ifFalse:[
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1388
                                digitByteArray := ByteArray new:8.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1389
                                digitByteArray at:1 put:b1.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1390
                                digitByteArray at:2 put:b2.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1391
                                digitByteArray at:3 put:b3.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1392
                                digitByteArray at:4 put:b4.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1393
                                digitByteArray at:5 put:b5.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1394
                                digitByteArray at:6 put:b6.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1395
                                digitByteArray at:7 put:b7.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1396
                                digitByteArray at:8 put:absValue.
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1397
                            ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1398
                        ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1399
                    ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1400
                ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1401
            ]
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1402
        ]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1403
    ]
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  1404
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1405
    "Modified: / 26.5.1999 / 22:18:14 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1406
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1407
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1408
!LargeInteger methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1409
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1410
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1411
    "return true, if the argument, aNumber is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1412
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1413
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1414
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1415
    (aNumber class == self class) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1416
	^ self retry:#< coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1417
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1418
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1419
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1420
    (sign > 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1421
	"I am positive"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1422
	(otherSign > 0) ifTrue:[^ self absLess:aNumber].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1423
	^ false "aNumber is <= 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1424
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1425
    (sign == 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1426
	(otherSign > 0) ifTrue:[^ true].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1427
	^ false
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1428
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1429
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1430
    (otherSign > 0) ifTrue:[^ true].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1431
    (otherSign == 0) ifTrue:[^ true].
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1432
    ^ (aNumber absLess:self)
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1433
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1434
    "Modified: / 14.1.1998 / 12:51:42 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1435
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1436
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1437
= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1438
    "return true, if the argument, aNumber has the same value as
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1439
     the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1440
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1441
    "/ speed up compare to 0
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1442
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1443
    (aNumber == 0 and:[sign == 0]) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
  1444
	^ true
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1445
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1446
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1447
    (aNumber class == self class) ifFalse:[
3424
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1448
	"/
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1449
	"/ 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
  1450
	"/ 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
  1451
	"/ 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
  1452
	"/
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1453
	aNumber class == SmallInteger ifTrue:[^ false ].
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1454
	aNumber respondsToArithmetic ifFalse:[ ^ false ].
39de1fface52 oops - negation of (maxInt+1) to minInt failed
Claus Gittinger <cg@exept.de>
parents: 3300
diff changeset
  1455
	^ self retry:#= coercing:aNumber
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1456
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1457
    (aNumber sign == sign) ifFalse:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1458
    ^ self absEq:aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1459
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1460
    "Modified: / 13.2.1998 / 11:43:15 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1461
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1462
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1463
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1464
    "return true, if the argument, aNumber is less than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1465
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1466
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1467
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1468
    (aNumber class == self class) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1469
	^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1470
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1471
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1472
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1473
    (sign > 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1474
	"I am positive"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1475
	(otherSign > 0) ifTrue:[^ aNumber absLess:self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1476
	^ true "aNumber is <= 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1477
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1478
    (sign == 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1479
	"I am zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1480
	(otherSign > 0) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1481
	^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1482
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1483
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1484
    (otherSign > 0) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1485
    (otherSign == 0) ifTrue:[^ false].
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1486
    ^ (self absLess:aNumber)  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1487
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1488
    "Modified: / 14.1.1998 / 12:56:56 / cg"
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1489
!
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1490
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1491
hash
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1492
    "return an integer useful for hashing on large numbers"
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1493
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1494
    ^ (self bitAnd:16r3FFFFFFF)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1495
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1496
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1497
!LargeInteger methodsFor:'double dispatching'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1498
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1499
differenceFromInteger:anInteger
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1500
    "sent, when anInteger does not know how to subtract the receiver.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1501
     Return the result of 'anInteger - self'. The argument must be a SmallInteger."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1502
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1503
    anInteger > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1504
	sign > 0 ifTrue:[
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1505
	    ^ self absFastMinus:anInteger sign:-1
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1506
	].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1507
	^ self absFastPlus:anInteger sign:1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1508
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1509
    anInteger == 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1510
	^ self negated
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1511
    ].
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1512
    sign > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1513
	^ self absFastPlus:anInteger negated sign:-1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1514
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1515
    ^ self absFastMinus:anInteger sign:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1516
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1517
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1518
     12345678901234567890          
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1519
     -12345678901234567890         
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1520
     12345678901234567890 differenceFromInteger:0       
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1521
     12345678901234567890 differenceFromInteger:1       
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1522
     12345678901234567890 differenceFromInteger:-1      
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1523
     -12345678901234567890 differenceFromInteger:1   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1524
     -12345678901234567890 differenceFromInteger:-1   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1525
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1526
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1527
    "Modified: 20.10.1996 / 18:41:54 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1528
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1529
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1530
productFromInteger:anInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1531
    "sent, when anInteger does not know how to multiply the receiver.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1532
     Return the product of the receiver and the argument, aSmallInteger"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1533
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1534
    |num result 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1535
     resultDigitByteArray
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1536
     val     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1537
     len     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1538
     carry   "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  1539
     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
  1540
     ok lResult|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1541
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1542
    "multiplying by a small integer is done here"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1543
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1544
    "trivial cases"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1545
    anInteger == 0 ifTrue:[^ 0].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1546
    anInteger == 1 ifTrue:[^ self].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1547
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1548
    num := anInteger abs.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1549
    (num > 16r3FFFFF) ifTrue:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1550
        "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
  1551
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1552
        ^ anInteger retry:#* coercing:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1553
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1554
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1555
    len := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1556
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1557
    val := num.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1558
    val <= 16rFF ifTrue:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1559
        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
  1560
    ] ifFalse:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1561
        val <= 16rFFFF ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1562
            lResult := len + 2
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1563
        ] ifFalse:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1564
            val <= 16rFFFFFF ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1565
                lResult := len + 4.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1566
            ] ifFalse:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1567
                lResult := len + 6.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1568
            ]
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1569
        ]
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1570
    ].
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  1571
    resultDigitByteArray := ByteArray uninitializedNew:lResult.
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2855
diff changeset
  1572
    result := self class basicNew setDigits:resultDigitByteArray.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1573
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1574
    anInteger < 0 ifTrue:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1575
        sign > 0 ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1576
            result sign:-1
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1577
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1578
    ] ifFalse:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1579
        sign < 0 ifTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1580
            result sign:sign
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1581
        ]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1582
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1583
85
claus
parents: 77
diff changeset
  1584
    ok := false.
claus
parents: 77
diff changeset
  1585
%{
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1586
    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
  1587
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1588
    if (__isSmallInteger(len)
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1589
     && __isByteArray(__digitByteArray)
85
claus
parents: 77
diff changeset
  1590
     && __isByteArray(resultDigitByteArray)) {
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1591
        INT _l = __intVal(len);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1592
        INT _v = __intVal(val);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1593
        unsigned INT _carry = 0;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1594
        unsigned INT _prod;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1595
        unsigned char *digitP = __ByteArrayInstPtr(__digitByteArray)->ba_element;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1596
        unsigned char *resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
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
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1599
         * skipping zeros does not help much (a few percent) on
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1600
         * a P5 or other CPUS with a fast multiplier. 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1601
         * 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
  1602
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1603
        while ((_l >= sizeof(INT)) && (((unsigned INT *)digitP)[0] == 0)) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1604
             ((unsigned long *)resultP)[0] = 0;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1605
            digitP += sizeof(INT);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1606
            resultP += sizeof(INT);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1607
            _l -= sizeof(INT);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1608
        }
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1609
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1610
#if defined(i386) || defined(alpha) /* XXX actually: LSB_FIRST */
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1611
# if defined (__GNUC__) && defined(i386)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1612
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1613
         * can do it long-word-wise;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1614
         * 32*32 -> 64 multiplication
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1615
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1616
        while (_l > 3) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1617
            unsigned __pHi, __pLow;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1618
	    unsigned __digit;
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1619
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1620
            /* 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1621
             * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1622
             * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1623
             */
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1624
	    __digit = ((unsigned long *)digitP)[0];
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1625
            asm ("mull %3               \n
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1626
                  addl %4,%%eax         \n
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1627
                  adcl $0,%%edx"    
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1628
                    : "=a"  (__pLow),
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1629
                      "=d"  (__pHi)
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1630
                    : "0"   (__digit),
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1631
                      "1"   ((unsigned long)(_v)),
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1632
                      "rm"  ((unsigned long)(_carry)) );
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1633
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1634
            ((unsigned long *)resultP)[0] = __pLow;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1635
            _carry = __pHi;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1636
            digitP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1637
            resultP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1638
            _l -= 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1639
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1640
# else /* not GNU-i386 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1641
#  if defined (WIN32) && defined(i386)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1642
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1643
         * can do it long-word-wise;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1644
         * 32*32 -> 64 multiplication
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1645
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1646
        while (_l > 3) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1647
            unsigned __pLow;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1648
            unsigned digit; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1649
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1650
            /* 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1651
             * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1652
             * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1653
             */
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1654
/*
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1655
            digit = ((unsigned long *)digitP)[0]; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1656
            edx::eax = (digit * _v);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1657
            edx::eax += _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1658
            ((unsigned long *)resultP)[0] = eax; -- pLow
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1659
            _carry = edx; -- pHigh
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1660
            digitP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1661
            resultP += 4;
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1662
*/
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1663
            digit = ((unsigned long *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1664
            asm {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1665
                mov   eax, digit
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1666
                mov   edx, _v
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1667
                mul   edx
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1668
                add   eax, _carry
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1669
                adc   edx, 0 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1670
                mov   __pLow, eax
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1671
                mov   _carry, edx
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
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1674
            ((unsigned long *)resultP)[0] = __pLow; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1675
            digitP += 4; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1676
            resultP += 4; 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1677
            _l -= 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1678
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1679
#  else /* not WIN32-i386 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1680
#   if defined(INT64)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1681
        if (_v <= 0xFFFFFFFFL) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1682
            /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1683
             * have a 64bit int type ... good
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1684
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1685
            UINT64 _prod64;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1686
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1687
            /* have 64bit ints; can do it int-wise
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1688
             *
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1689
             * max: 0xFFFFFFFF * 0xFFFFFFFF -> 0xFFFFFFFE.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1690
             * + maxCarry (0xFFFFFFFF)  -> 0xFFFFFFFF.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1691
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1692
            while (_l > 3) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1693
                unsigned __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1694
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1695
                __t = ((unsigned *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1696
                digitP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1697
                _prod64 = (INT64)_v;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1698
                _prod64 *= __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1699
                _prod64 += _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1700
                ((unsigned *)resultP)[0] = _prod64 /* & 0xFFFFFFFFL */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1701
                _carry = _prod64 >> 32;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1702
                resultP += 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1703
                _l -= 4;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1704
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1705
            if (_l > 1) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1706
                unsigned short __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1707
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1708
                __t = ((unsigned short *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1709
                digitP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1710
                _prod64 = (INT64)_v;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1711
                _prod64 *= __t;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1712
                _prod64 += _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1713
                ((unsigned short *)resultP)[0] = _prod64 /* & 0xFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1714
                _carry = _prod64 >> 16;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1715
                resultP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1716
                _l -= 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1717
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1718
            if (_l > 0) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1719
                _prod64 = *digitP++ * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1720
                *resultP++ = _prod64 /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1721
                _carry = _prod64 >> 8;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1722
                _l--;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1723
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1724
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1725
#   else /* no INT64 type */
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1726
        if (_v <= 0xFFFF) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1727
            /* can do it short-wise 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1728
             * 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1729
             * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1730
             * + maxCarry (0xFFFF)  -> 0xFFFF.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1731
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1732
            while (_l > 1) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1733
                _prod = ((unsigned short *)digitP)[0] * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1734
                ((unsigned short *)resultP)[0] = _prod /* & 0xFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1735
                _carry = _prod >> 16;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1736
                digitP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1737
                resultP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1738
                _l -= 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1739
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1740
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1741
#   endif /* no INT64 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1742
#  endif /* not WIN32-i386 */
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  1743
# endif /* not GNU-i386 */
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  1744
#else /* not LSB_FIRST */
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1745
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1746
# ifdef mips
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1747
#  define LOAD_WORD_WISE
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1748
   /* 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
  1749
# endif
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1750
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1751
        if (_v <= 0xFFFF) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1752
            /* can do it short-wise 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1753
             * 
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1754
             * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1755
             * + maxCarry (0xFFFF)  -> 0xFFFF.0000
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1756
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1757
            while (_l > 1) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1758
                unsigned int t;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1759
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1760
#if defined(LOAD_WORD_WISE)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1761
                /* better fetch short-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1762
                t = ((unsigned short *)digitP)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1763
                digitP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1764
                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
  1765
#else
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1766
                t = (digitP[1]<<8) + digitP[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1767
                digitP += 2;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1768
#endif
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1769
                _prod = t * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1770
                _carry = _prod >> 16;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1771
#if defined(STORE_WORD_WISE)
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1772
                /* better store short-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1773
                _prod = ((_prod >> 8) | (_prod << 8)) & 0xFFFF;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1774
                ((unsigned short *)resultP)[0] = _prod;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1775
#else
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1776
                resultP[0] = _prod /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1777
                resultP[1] = (_prod>>8) /* & 0xFF */;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1778
#endif
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1779
                resultP += 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1780
                _l -= 2;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1781
            }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1782
        }
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  1783
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  1784
#endif /* LSB_FIRST */
1797
8dafe47b33fd faster multiplication by an integer.
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
  1785
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1786
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1787
         * rest is done byte-wise
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1788
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1789
        while (_l > 0) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1790
            _prod = *digitP++ * _v + _carry;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1791
            *resultP++ = _prod /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1792
            _carry = _prod >> 8;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1793
            _l--;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1794
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1795
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1796
        _l = __intVal(lResult) - __intVal(len);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1797
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1798
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1799
         * remaining carry
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1800
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1801
        while (_carry) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1802
            *resultP++ = _carry /* & 0xFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1803
            _carry >>= 8;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1804
            _l--;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1805
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1806
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1807
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1808
         * remaining zeros
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1809
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1810
        while (_l--) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1811
            *resultP++ = 0;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1812
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1813
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1814
        /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1815
         * need compress ?
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1816
         */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1817
        if (resultP[-1]) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1818
            /*
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1819
             * no
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1820
             */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1821
            RETURN(result);
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1822
        }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1823
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1824
        ok = true;
85
claus
parents: 77
diff changeset
  1825
    }
claus
parents: 77
diff changeset
  1826
%}.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1827
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1828
     fall back - normally not reached
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1829
     (could make it a primitive-failure as well)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1830
    "
85
claus
parents: 77
diff changeset
  1831
    ok ifFalse:[
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1832
        carry := 0.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1833
        1 to:len do:[:i |
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1834
            prod := (digitByteArray basicAt:i) * val + carry.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1835
            resultDigitByteArray basicAt:i put:(prod bitAnd:16rFF).
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1836
            carry := prod bitShift:-8.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1837
        ].
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1838
        [carry ~~ 0] whileTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1839
            len := len + 1.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1840
            resultDigitByteArray basicAt:len put:(carry bitAnd:16rFF).
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1841
            carry := carry bitShift:-8
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1842
        ].
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1843
        [len < lResult] whileTrue:[
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1844
            len := len + 1.
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1845
            resultDigitByteArray basicAt:len put:0
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1846
        ]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1847
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1848
    ^ result compressed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1849
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1850
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1851
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1852
    "sent, when anInteger does not know how to add the receiver.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1853
     Return the sum of the receiver and the argument, (which must be a SmallInteger)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1854
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1855
    anInteger > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1856
	sign > 0 ifTrue:[
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1857
	    ^ self absFastPlus:anInteger sign:1
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1858
	].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1859
	^ self absFastMinus:anInteger sign:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1860
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1861
    anInteger == 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1862
	^ self
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1863
    ].
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1864
    sign > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1865
	^ self absFastMinus:anInteger sign:1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1866
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1867
    ^ self absFastPlus:anInteger sign:-1
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1868
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1869
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1870
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1871
     12345678901234567890          
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1872
     -12345678901234567890         
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1873
     12345678901234567890 sumFromInteger:0       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1874
     -12345678901234567890 sumFromInteger:0       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1875
     12345678901234567890 sumFromInteger:1       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1876
     12345678901234567890 sumFromInteger:-1      
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1877
     -12345678901234567890 sumFromInteger:1     
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1878
     -12345678901234567890 sumFromInteger:-1   
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1879
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1880
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1881
    "Modified: / 9.1.1998 / 13:27:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1882
! !
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1883
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1884
!LargeInteger methodsFor:'printing & storing'!
345
claus
parents: 250
diff changeset
  1885
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1886
storeOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1887
    "append a representation of the receiver to aStream, which can
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1888
     be used to reconstruct the receiver."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1889
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1890
    self printOn:aStream.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1891
    aStream nextPutAll:' asLargeInteger'
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1892
! !
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1893
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1894
!LargeInteger methodsFor:'private'!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1895
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1896
absDivMod:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1897
    "return an array with two LargeIntegers representing
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1898
     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
  1899
     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
  1900
     This method needs a rewrite."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1901
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1902
    |dividend divisor 
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1903
     quo digits
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1904
     shift "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1905
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1906
    anInteger == 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1907
        ^ DivisionByZeroSignal raiseRequest
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1908
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1909
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1910
    self = anInteger ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1911
        ^ Array with:1 with:0
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1912
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1913
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1914
    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
  1915
    dividend := self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1916
    shift < 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1917
        ^ Array with:0 with:dividend.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1918
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  1919
    shift == 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1920
        divisor := anInteger simpleDeepCopy.
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  1921
    ] ifFalse:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1922
        divisor := anInteger bitShift:shift.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1923
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1924
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1925
    quo := self class basicNew numberOfDigits:((shift // 8) + 1). 
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1926
    digits := quo digitBytes.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1927
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1928
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1929
    [shift > 0] whileTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1930
        (dividend absLess:divisor) ifFalse:[
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1931
            digits bitSetAt:shift.
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1932
            (dividend absSubtract: divisor) ifFalse:[ "result == 0"
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1933
                ^ Array with:quo compressed with:dividend compressed            
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1934
            ].
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1935
        ].
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1936
        shift := shift - 1.
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1937
        divisor div2.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1938
    ].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1939
    ^ 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
  1940
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1941
    "
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1942
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:4000000000] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1943
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:3000000000] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1944
     16000000000 absDivMod:4000000000 
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1945
     16000000000 absDivMod:3000000000
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1946
    "
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1947
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1948
    "Modified: / 5.11.1996 / 18:40:24 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1949
    "Created: / 27.4.1999 / 19:45:44 / stefan"
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  1950
    "Modified: / 26.7.1999 / 10:46:36 / stefan"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1951
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1952
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1953
absEq:aLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1954
    "return true, if abs(self) = abs(theArgument)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1955
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1956
    |len1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1957
     len2 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1958
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1959
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1960
     otherDigitByteArray |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1961
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1962
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1963
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1964
    len2 := otherDigitByteArray size.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1965
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1966
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1967
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1968
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1969
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1970
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1971
    [(digitByteArray basicAt:len1) == 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1972
        len1 := len1 - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1973
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1974
    [(otherDigitByteArray basicAt:len2) == 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1975
        len2 := len2 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1976
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1977
    (len1 ~~ len2) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1978
    [len1 > 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1979
        d1 := digitByteArray basicAt:len1.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1980
        d2 := otherDigitByteArray basicAt:len1.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1981
        (d1 ~~ d2) ifTrue:[^ false].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1982
        len1 := len1 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1983
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1984
    ^ true
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1985
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  1986
    "Modified: / 8.5.1999 / 18:37:02 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1987
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1988
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  1989
absFastDivMod:aPositiveSmallInteger
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1990
    "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
  1991
     abs(self) // aPositiveSmallInteger and 
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1992
     abs(self) \\ aPositiveSmallInteger."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1993
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1994
    |tmp1     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1995
     prevRest "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1996
     count    "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  1997
     newDigitByteArray result
claus
parents: 77
diff changeset
  1998
     ok|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1999
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2000
    aPositiveSmallInteger == 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  2001
        ^ DivisionByZeroSignal raiseRequest
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2002
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2003
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2004
"This cannot happen (if always normalized)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2005
    self < aPositiveSmallInteger ifTrue:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2006
        ^ Array with:0 with:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2007
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2008
"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2009
    count := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2010
    result := self class basicNew numberOfDigits:count.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2011
    newDigitByteArray := result digitBytes.
85
claus
parents: 77
diff changeset
  2012
    ok := false.
claus
parents: 77
diff changeset
  2013
%{
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2014
    OBJ __digits;
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2015
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2016
    __digits = __INST(digitByteArray);
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2017
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2018
    if (__isByteArray(__digits)
85
claus
parents: 77
diff changeset
  2019
     && __isByteArray(newDigitByteArray)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2020
     && __bothSmallInteger(count, aPositiveSmallInteger)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2021
        unsigned INT rest = 0;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2022
        int index = __intVal(count);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2023
        int index0;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2024
        unsigned INT divisor = __intVal(aPositiveSmallInteger);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2025
        unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2026
        unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2027
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2028
        index0 = index - 1;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2029
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2030
        /* 
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2031
         * divide short-wise 
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2032
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2033
        if (divisor <= 0xFFFF) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2034
            if ((index & 1) == 0) { /* even number of bytes */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2035
                while (index > 1) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2036
                    unsigned INT t;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2037
                    unsigned INT div;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2038
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2039
                    index -= 2;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2040
#if defined(__LSBFIRST) || defined(i386)
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2041
                    t = *((unsigned short *)(&digitBytes[index]));
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2042
#else
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2043
                    t = digitBytes[index+1];
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2044
                    t = (t << 8) | digitBytes[index];
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2045
#endif
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2046
                    t = t | (rest << 16);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2047
                    div = t / divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2048
                    rest = t % divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2049
#if defined(__LSBFIRST) || defined(i386)
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2050
                    *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2051
#else
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2052
                    resultBytes[index+1] = div >> 8;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2053
                    resultBytes[index] = div /* & 0xFF */;
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2054
#endif
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2055
                }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2056
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2057
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2058
        while (index > 0) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2059
            unsigned INT t;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2060
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2061
            index--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2062
            t = digitBytes[index];
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2063
            t = t | (rest << 8);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2064
            resultBytes[index] = t / divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2065
            rest = t % divisor;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2066
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2067
        prevRest = __MKSMALLINT(rest);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2068
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2069
        /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2070
         * no need to normalize ?
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2071
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2072
        while ((index0 >= sizeof(INT)) && (resultBytes[index0]==0)) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2073
            index0--;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2074
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2075
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2076
        if (index0 > sizeof(INT)) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2077
            RETURN ( __ARRAY_WITH2(result, prevRest));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2078
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2079
        if ((index0 == sizeof(INT))
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2080
         && resultBytes[index0] >= 0x40) {
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2081
            RETURN ( __ARRAY_WITH2(result, prevRest));
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2082
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2083
        /*
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2084
         * must compress
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2085
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2086
        ok = true;
85
claus
parents: 77
diff changeset
  2087
    }
claus
parents: 77
diff changeset
  2088
%}.
claus
parents: 77
diff changeset
  2089
    "
claus
parents: 77
diff changeset
  2090
     slow code - not normally reached
claus
parents: 77
diff changeset
  2091
     (could also do a primitiveFailure here)
claus
parents: 77
diff changeset
  2092
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2093
    ok ifFalse:[
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2094
        self primitiveFailed
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2095
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2096
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  2097
    ^ 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
  2098
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2099
    "
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2100
     ((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
  2101
     ((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
  2102
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2103
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2104
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2105
absFastMinus:aSmallInteger sign:newSign
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2106
    "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
  2107
     with sign: newSign.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2108
     The result is normalized.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2109
     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
  2110
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2111
    |result resultDigitByteArray lastDigit ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2112
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2113
     rsltLen "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2114
     index   "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2115
     borrow  "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2116
     diff    "{ Class: SmallInteger }" |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2117
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2118
    "/ the following code only works with
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2119
    "/ 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
  2120
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2121
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2122
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2123
        ^ 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
  2124
    ]. 
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2125
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2126
    len := digitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2127
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2128
    rsltLen := len "+ 1".
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2129
    result := self class basicNew numberOfDigits:rsltLen.
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2130
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2131
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2132
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2133
    borrow := aSmallInteger abs.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2134
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2135
%{
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2136
    if (__isByteArray(__INST(digitByteArray))
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2137
     && __isByteArray(resultDigitByteArray)) {
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2138
        unsigned INT __borrow = __intVal(borrow);
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2139
        INT __diff;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2140
        int __index = 1;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2141
        int __len = __intVal(len);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2142
        unsigned char *__digitP = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2143
        unsigned char *__resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2144
        int __len3;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2145
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2146
#if defined(alpha64)
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2147
        /* 
4948
adfadf9b2c75 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4947
diff changeset
  2148
         * subtract int-wise 
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2149
         */
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2150
        __len3 = __len - 3;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2151
        while (__index < __len3) {
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2152
            /* do not make this into one expression - ask cg why */
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2153
            __diff = ((unsigned int *)(__digitP + __index-1))[0];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2154
            __diff -= (__borrow & 0xFFFFFFFFL);
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2155
            __borrow >>= 32;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2156
            if (__diff < 0) {
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2157
                /* __diff += 0x100000000; */
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2158
                __borrow++;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2159
            }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2160
            ((unsigned int *)(__resultP+__index-1))[0] = __diff;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2161
            __index += 4;
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2162
        }
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2163
#endif
4182
a867ecbf5e56 tuned abdFastMinus:
Claus Gittinger <cg@exept.de>
parents: 4181
diff changeset
  2164
#if defined(__LSBFIRST) || defined(i386)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2165
        /* 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2166
         * subtract short-wise 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2167
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2168
        while (__index < __len) {
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2169
            /* do not make this into one expression - ask cg why */
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2170
            __diff = ((unsigned short *)(__digitP+__index-1))[0];
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2171
            __diff -= (__borrow & 0xFFFF);
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2172
            __borrow >>= 16;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2173
            if (__diff < 0) {
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2174
                /* __diff += 0x10000; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2175
                __borrow++;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2176
            } else {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2177
                if (__borrow == 0) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2178
                    ((unsigned short *)(__resultP+__index-1))[0] = __diff;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2179
                    __index += 2;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2180
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2181
                    /* nothing more to subtract .. */
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2182
                    while (__index < __len) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2183
                        ((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
  2184
                        __index += 2;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2185
                    }
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2186
                    if (__index <= __len) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2187
                        __resultP[__index-1] = __digitP[__index-1];
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2188
                    }
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2189
                    break;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2190
                }
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2191
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2192
            ((unsigned short *)(__resultP+__index-1))[0] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2193
            __index += 2;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2194
        }
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2195
#endif
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2196
        /* 
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2197
         * subtract byte-wise 
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2198
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2199
        while (__index <= __len) {
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2200
            __diff = __digitP[__index-1];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2201
            __diff -= (__borrow & 0xFF);
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2202
            __borrow >>= 8;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2203
            if (__diff < 0) {
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2204
                /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2205
                __borrow++;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2206
            } else {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2207
                if (__borrow == 0) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2208
                    __resultP[__index-1] = __diff;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2209
                    __index++;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2210
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2211
                    /* nothing more to subtract .. */
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2212
                    while (__index <= __len) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2213
                        __resultP[__index-1] = __digitP[__index-1];
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2214
                        __index++;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2215
                    }
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2216
                    break;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2217
                }
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2218
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2219
            __resultP[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2220
            __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2221
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2222
        lastDigit = __MKSMALLINT( __resultP[__index-1-1] );
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2223
        ok = true;
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2224
    }
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2225
%}.
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2226
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2227
    ok == true ifFalse:[        "/ cannot happen
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2228
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2229
        [borrow ~~ 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2230
            (index <= len) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2231
                diff := (digitByteArray basicAt:index) - (borrow bitAnd:16rFF).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2232
                borrow := borrow bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2233
                diff < 0 ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2234
                    diff := diff + 256.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2235
                    borrow := borrow + 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2236
                ]
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2237
            ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2238
                diff := borrow bitAnd:255.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2239
                borrow := borrow bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2240
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2241
            resultDigitByteArray basicAt:index put:(lastDigit := diff).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2242
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2243
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2244
        [index <= len] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2245
            resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2246
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2247
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2248
        (index <= rsltLen) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2249
            lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2250
        ]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2251
    ].
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2252
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2253
    (lastDigit == 0 or:[rsltLen <= SmallInteger maxBytes]) ifTrue:[ 
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2254
        ^ result compressed.
4182
a867ecbf5e56 tuned abdFastMinus:
Claus Gittinger <cg@exept.de>
parents: 4181
diff changeset
  2255
    ]. 
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2256
    ^ result
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2257
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2258
    "                                                          
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2259
     12345678900000000000 absFastMinus:1 sign:1       
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2260
     12345678900000000000 absFastMinus:1 sign:-1      
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2261
     12345678900000000000 absFastMinus:1000000 sign:1 
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2262
     12345678900000000000 absFastMinus:255 sign:1     
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2263
     (SmallInteger maxVal + 1) absFastMinus:1 sign:1
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2264
     (SmallInteger minVal - 1) absFastMinus:1 sign:1  
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2265
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2266
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2267
    "Modified: 24.3.1997 / 21:33:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2268
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2269
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2270
absFastPlus:aSmallInteger sign:newSign
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2271
    "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
  2272
     with sign: newSign.
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2273
     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
  2274
     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
  2275
     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
  2276
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2277
    |result resultDigitByteArray lastDigit
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2278
     ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2279
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2280
     rsltLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2281
     index "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2282
     carry "{ Class: SmallInteger }" |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2283
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2284
    "/ the following code only works with
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2285
    "/ 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
  2286
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2287
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2288
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2289
        ^ 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
  2290
    ]. 
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2291
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2292
    len := rsltLen := digitByteArray size.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2293
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2294
    "/ 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
  2295
    "/ 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
  2296
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2297
    (digitByteArray at:len) == 16rFF ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2298
        rsltLen := len + 1.
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2299
    ] ifFalse:[
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2300
        "/ or the argument has something in the high byte ..
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2301
%{
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2302
#ifdef alpha64
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2303
        if (__intVal(aSmallInteger) & 0xFF00000000000000L) {
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2304
            rsltLen = __MKSMALLINT(__intVal(len) + 1);
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2305
        }
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2306
#else
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2307
        if (__intVal(aSmallInteger) & 0xFF000000) {
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2308
            rsltLen = __MKSMALLINT(__intVal(len) + 1);
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2309
        }
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2310
#endif
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2311
%}
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2312
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2313
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2314
    result := self class basicNew numberOfDigits:rsltLen.
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2315
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2316
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2317
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2318
%{
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2319
    if (__isByteArray(__INST(digitByteArray))
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2320
     && __isByteArray(resultDigitByteArray)
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2321
     && __isSmallInteger(aSmallInteger)) {
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2322
        /* carry is NOT unsigned (see negation below) */
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2323
        INT __carry = __intVal(aSmallInteger);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2324
        int __index = 1;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2325
        int __len = __intVal(len);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2326
        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
  2327
        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
  2328
        INT __ptrDelta = __dst - __src;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2329
        unsigned char *__srcLast = __src + __len - 1;
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2330
        int __rsltLen = __intVal(rsltLen);
4213
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
        if (__carry < 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2333
            __carry = -__carry;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2334
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2335
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2336
#if defined(__LSBFIRST) || defined(i386) || defined(alpha)
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2337
# if defined(i386) && defined(__GNUC__)
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2338
#  if 0 /* NOTICE - the code below is 20% slower ... - why */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2339
        /*
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2340
         * add long-wise
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2341
         */
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2342
        asm("  jecxz nothingToDo     
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2343
               movl  %%eax, %%esi      /* __src input */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2344
               movl  %%ebx, %%edi      /* __dst input */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2345
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2346
               /* the first 4-byte int */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2347
               lodsl                   /* fetch */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2348
               addl  %%edx, %%eax      /* add */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2349
               stosl                   /* store */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2350
               leal  -1(%%ecx),%%ecx   /* do not clobber carry */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2351
               jecxz doneLoop          /* any more ? */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2352
               /* remaining 4-byte ints */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2353
               jmp   addLoop
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2354
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2355
               .align 8
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2356
             addLoop:
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2357
               movl  0(%%esi), %%ebx   /* fetch  */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2358
               jnc   copyLoop2
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2359
               movl  $0, %%eax 
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2360
               leal  4(%%esi), %%esi   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2361
               adcl  %%ebx, %%eax      /* & add carry from prev int */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2362
               leal  8(%%edi), %%edi   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2363
               movl  %%eax, -8(%%edi)  /* store */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2364
               leal  -1(%%ecx),%%ecx   /* do not clobber carry */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2365
               jecxz doneLoop          /* any more ? */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2366
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2367
               movl  0(%%esi), %%ebx   /* fetch  */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2368
               movl  $0, %%eax 
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2369
               leal  4(%%esi), %%esi   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2370
               adcl  %%ebx, %%eax      /* & add carry from prev int */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2371
               movl  %%eax, -4(%%edi)  /* store */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2372
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2373
               loop  addLoop
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2374
               jmp   doneLoop
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2375
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2376
               .align 8
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2377
             copyLoop:
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2378
               movl  0(%%esi), %%ebx   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2379
             copyLoop2:
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2380
               add   $4, %%esi   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2381
               add   $4, %%edi   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2382
               movl  %%ebx, -4(%%edi)   
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2383
               loop  copyLoop
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2384
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2385
             doneLoop:
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2386
               movl  $0, %%edx         /* do not clobber carry (xorl clears it) */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2387
               adcl  $0, %%edx
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2388
               movl  %%esi, %%eax      /* __src output */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2389
             nothingToDo:           
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2390
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2391
            " : "=d"  ((unsigned long)(__carry)),
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2392
                "=a"  (__src)
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2393
              : "1"   (__src),
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2394
                "b"   (__dst),
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2395
                "c"   (__len / 4),
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2396
                "0"   (__carry)
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2397
              : "esi", "edi");
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2398
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2399
#  else
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2400
        {
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2401
            unsigned char *__srcLastX;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2402
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2403
            __srcLastX = __srcLast - 3 - 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2404
            while (__src <= __srcLastX) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2405
                unsigned int __sum, __sum2;
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2406
                unsigned __digit1, __digit2;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2407
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2408
                __digit1 = ((unsigned *)__src)[0];
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2409
                __digit2 = ((unsigned *)__src)[1];
4286
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2410
                asm ("addl %%edx,%%ecx
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2411
                      adcl $0, %%eax
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2412
                      movl $0, %%edx
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2413
                      adcl $0, %%edx"    
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2414
                        : "=d"  ((unsigned long)(__carry)),
4286
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2415
                          "=c"  ((unsigned long)(__sum)),
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2416
                          "=a"  ((unsigned long)(__sum2))
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2417
                        : "0"   ((unsigned long)(__carry)),
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2418
                          "1"   (__digit1),
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2419
                          "2"   (__digit2));
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2420
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2421
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2422
                ((unsigned int *)(__src + __ptrDelta))[1] = __sum2;
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2423
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2424
                __src += 8;  
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2425
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2426
                if (__carry == 0) {
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2427
                    while (__src <= __srcLastX) {
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2428
                        /* copy over words */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2429
                        ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2430
                        ((unsigned int *)(__src + __ptrDelta))[1] = ((unsigned int *)__src)[1];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2431
                        __src += 8;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2432
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2433
                    while (__src <= __srcLast) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2434
                        /* copy over bytes */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2435
                        __src[__ptrDelta] = __src[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2436
                        __src ++;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2437
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2438
                    goto doneSource;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2439
                }
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2440
            }
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2441
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2442
            __srcLastX = __srcLastX + 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  2443
            if (__src <= __srcLastX) {
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2444
                unsigned int __sum, __digit;
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2445
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2446
                __digit = ((unsigned *)__src)[0];
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2447
4286
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2448
                asm ("addl %%eax,%%edx
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2449
                      movl $0,%%eax
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2450
                      adcl $0,%%eax"    
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2451
                        : "=a"  ((unsigned long)(__carry)),
2cfcccd2f1ca Fix asm for gcc2.7.2
Stefan Vogel <sv@exept.de>
parents: 4284
diff changeset
  2452
                          "=d"  ((unsigned long)(__sum))
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2453
                        : "0"   ((unsigned long)(__carry)),
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2454
                          "1"   (__digit) );
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2455
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2456
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2457
                __src += 4;  
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2458
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2459
                if (__carry == 0) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2460
                    while (__src <= __srcLast) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2461
                        /* copy over bytes */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2462
                        __src[__ptrDelta] = __src[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2463
                        __src ++;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2464
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2465
                    goto doneSource;
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2466
                }
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2467
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2468
        }
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2469
#  endif
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2470
# else 
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2471
#  if defined(i386) && defined(WIN32)
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2472
        {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2473
            unsigned char *__srcLast4;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2474
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2475
            /*
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2476
             * add long-wise
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2477
             */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2478
            __srcLast4 = __srcLast - 3;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2479
            while (__src <= __srcLast4) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2480
                unsigned int __sum;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2481
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2482
                __sum = ((unsigned int *)__src)[0];    
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2483
                asm {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2484
                      mov eax, __sum
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2485
                      add eax, __carry
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2486
                      mov edx, 0
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2487
                      adc edx, 0
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2488
                      mov __sum, eax
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2489
                      mov __carry, edx
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2490
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2491
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2492
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2493
                __src += 4;  
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2494
                if (__carry == 0) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2495
                    while (__src <= __srcLast4) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2496
                        /* copy over words */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2497
                        ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2498
                        __src += 4;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2499
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2500
                    while (__src <= __srcLast) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2501
                        /* copy over bytes */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2502
                        __src[__ptrDelta] = __src[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2503
                        __src ++;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2504
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2505
                    goto doneSource;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2506
                }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2507
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2508
        }
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2509
#  else 
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2510
#   ifdef alpha64
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2511
        {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2512
            unsigned char *__srcLast4;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2513
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2514
            /*
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2515
             * add long-wise
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2516
             */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2517
            __srcLast4 = __srcLast - 3;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2518
            while (__src <= __srcLast4) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2519
                unsigned INT __sum;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2520
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2521
                __sum = ((unsigned int *)__src)[0] + __carry;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2522
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum /* & 0xFFFF */;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2523
                __src += 4;  
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2524
                __carry = __sum >> 32;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2525
                if (__carry == 0) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2526
                    while (__src <= __srcLast4) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2527
                        /* copy over words */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2528
                        ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2529
                        __src += 4;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2530
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2531
                    while (__src <= __srcLast) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2532
                        /* copy over bytes */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2533
                        __src[__ptrDelta] = __src[0];
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2534
                        __src ++;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2535
                    }
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2536
                    goto doneSource;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2537
                }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2538
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2539
        }
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2540
#   endif /* alpha64 */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2541
#  endif /* i386 & WIN32 */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2542
# endif /* i386 & GNUC */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2543
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2544
        /*
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2545
         * add short-wise
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2546
         */
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2547
        while (__src < __srcLast) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2548
            __carry += ((unsigned short *)__src)[0];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2549
            ((unsigned short *)(__src + __ptrDelta))[0] = __carry /* & 0xFFFF */;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2550
            __carry >>= 16;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2551
            __src += 2;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2552
        }
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2553
        /*
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2554
         * last (odd) byte
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2555
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2556
        if (__src <= __srcLast) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2557
            __carry += __src[0];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2558
            __src[__ptrDelta] = __carry /* & 0xFF */;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2559
            __carry >>= 8;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2560
            __src++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2561
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2562
#else /* not __LSBFIRST */
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2563
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2564
        /*
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2565
         * add byte-wise
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2566
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2567
        while (__src <= __srcLast) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2568
            __carry += __src[0];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2569
            __src[__ptrDelta] = __carry /* & 0xFF */;
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2570
            __src++;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2571
            __carry >>= 8;
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2572
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2573
            if (__carry == 0) {
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2574
                while (__src <= __srcLast) {
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2575
                    /* copy over rest */
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2576
                    __src[__ptrDelta] = __src[0];
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2577
                    __src++;
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2578
                }
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2579
                goto doneSource;
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2580
            }
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2581
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2582
#endif /* __LSBFIRST */
4185
375439993eb7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4182
diff changeset
  2583
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2584
    doneSource: ;
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2585
        /*
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2586
         * now, at most one other byte is to be stored ...
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2587
         */
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2588
        if (__len < __rsltLen) {
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2589
            __src[__ptrDelta] = __carry /* & 0xFF */;
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2590
            __src++;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2591
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2592
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2593
        if (__src[__ptrDelta-1]) {      /* lastDigit */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2594
            RETURN (result);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2595
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2596
        ok = true;
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2597
    }
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2598
%}.
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2599
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2600
    ok ~~ true ifTrue:[
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
        carry := aSmallInteger abs.
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
        [carry ~~ 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2605
            (index <= len) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2606
                carry := (digitByteArray basicAt:index) + carry.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2607
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2608
            resultDigitByteArray basicAt:index put:(lastDigit := carry bitAnd:16rFF).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2609
            carry := carry bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2610
            index := index + 1
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
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2613
        (index <= rsltLen) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2614
            [index <= len] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2615
                resultDigitByteArray basicAt:index put:(digitByteArray basicAt:index).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2616
                index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2617
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2618
            lastDigit := 0.
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
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2621
        (lastDigit ~~ 0 and:[rsltLen > SmallInteger maxBytes]) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2622
            ^ result
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2623
        ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2624
    ].
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2625
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2626
    ^ result compressed
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2627
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2628
    "Modified: 24.3.1997 / 21:32:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2629
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2630
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2631
absLess:aLargeInteger
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2632
    "return true, if abs(self) < abs(theArgument).
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2633
     This handles unnormalized largeIntegers."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2634
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2635
    |myLen "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2636
     otherLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2637
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2638
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2639
     otherDigitByteArray |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2640
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2641
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2642
    otherDigitByteArray := aLargeInteger digitBytes.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2643
    otherLen := otherDigitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2644
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2645
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2646
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2647
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2648
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2649
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2650
    [myLen > 0 and:[(digitByteArray basicAt:myLen) == 0]] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2651
        myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2652
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2653
    [otherLen > 0 and:[(otherDigitByteArray basicAt:otherLen) == 0]] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2654
        otherLen := otherLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2655
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2656
    (myLen < otherLen) ifTrue:[^ true].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2657
    (myLen > otherLen) ifTrue:[^ false].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2658
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2659
    [myLen > 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2660
        d1 := digitByteArray basicAt:myLen.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2661
        d2 := otherDigitByteArray basicAt:myLen.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2662
        d1 == d2 ifFalse:[
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2663
            (d1 < d2) ifTrue:[^ true].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2664
            ^ false
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2665
        ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2666
        myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2667
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2668
    ^ false
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2669
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2670
    "Modified: / 3.5.1999 / 08:06:28 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2671
    "Modified: / 8.5.1999 / 18:37:11 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2672
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2673
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2674
absLessEq:aLargeInteger
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2675
    "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
  2676
     This handles unnormalized largeIntegers."
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2677
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2678
    |myLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2679
     otherLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2680
     d1   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2681
     d2   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2682
     otherDigitByteArray |
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2683
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2684
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2685
    otherDigitByteArray := aLargeInteger digitBytes.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2686
    otherLen := otherDigitByteArray size.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2687
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2688
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2689
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2690
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2691
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2692
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2693
    [(digitByteArray basicAt:myLen) == 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2694
        myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2695
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2696
    [(otherDigitByteArray basicAt:otherLen) == 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2697
        otherLen := otherLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2698
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2699
    (myLen < otherLen) ifTrue:[^ true].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2700
    (myLen > otherLen) ifTrue:[^ false].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2701
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2702
    [myLen > 0] whileTrue:[
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2703
        d1 := digitByteArray basicAt:myLen.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2704
        d2 := otherDigitByteArray basicAt:myLen.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2705
        d1 == d2 ifFalse:[
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2706
            (d1 < d2) ifTrue:[^ true].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2707
            ^ false.
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2708
        ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2709
        myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2710
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2711
    ^ true
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2712
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2713
    "Created: / 13.2.1998 / 12:19:45 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2714
    "Modified: / 30.4.1999 / 12:46:31 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2715
    "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
  2716
!
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2717
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2718
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
  2719
    "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
  2720
     with sign: newSign.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2721
     The result is normalized. The argument must be a largeInteger
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2722
     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
  2723
     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
  2724
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2725
    |result done
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2726
     otherDigitByteArray resultDigitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2727
     len1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2728
     len2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2729
     index  "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2730
     borrow "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2731
     diff   "{ Class: SmallInteger }"
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2732
     carry  "{ Class: SmallInteger }" 
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2733
     lastDigit   
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2734
     lResult ok|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2735
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2736
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2737
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2738
    len2 := otherDigitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2739
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2740
    len1 > len2 ifTrue:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2741
        lResult := len1
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2742
    ] ifFalse:[
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2743
        lResult := (len1 max: len2) + 1.
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2744
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2745
    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
  2746
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2747
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2748
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2749
    lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2750
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2751
%{
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2752
    OBJ _digitByteArray = __INST(digitByteArray);
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2753
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2754
    if (__isByteArray(_digitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2755
     && __isByteArray(otherDigitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2756
     && __isByteArray(resultDigitByteArray)) {
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2757
        int __len1 = __intVal(len1);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2758
        int __len2 = __intVal(len2);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2759
        int __minLen = __len1 < __len2 ? __len1 : __len2;
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2760
        int __index, __borrow = 0;
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2761
        INT __diff;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2762
        unsigned char *__myDigits, *__otherDigits, *__resultDigits;
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2763
        
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2764
        ok = true;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2765
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2766
        __resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2767
        __otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2768
        __myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2769
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2770
        __index = 1;
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2771
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2772
#if defined(alpha64)
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2773
        /*
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2774
         * subtract int-wise
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2775
         */
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2776
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2777
        while ((__index+3) <= __minLen) {
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2778
            /* do not make this into one expression - ask cg why */
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2779
            __diff = ((unsigned int *)(__myDigits+__index-1))[0]; 
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2780
            __diff -= ((unsigned int *)(__otherDigits+__index-1))[0];
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2781
            __diff -= __borrow;
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2782
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2783
            if (__diff >= 0) {
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2784
                __borrow = 0;
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2785
            } else {
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2786
                __borrow = 1;
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2787
                /* __diff += 0x10000; */
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2788
            }
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2789
            ((unsigned int *)(__resultDigits+__index-1))[0] = __diff;
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2790
            __index += 4;
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2791
        }
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2792
#endif /* alpha64 */
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2793
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2794
#if defined(i386) || defined(__LSBFIRST)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2795
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2796
         * subtract short-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2797
         */
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2798
        while (__index < __minLen) {   /* i.e. index+1 <= minLen */
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2799
            /* do not make this into one expression - ask cg why */
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2800
            __diff = ((unsigned short *)(__myDigits+__index-1))[0];
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2801
            __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2802
            __diff -= __borrow;
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2803
            if (__diff >= 0) {
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2804
                __borrow = 0;
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2805
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2806
                __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2807
                /* __diff += 0x10000; */
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2808
            }
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2809
            ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2810
            __index += 2;
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2811
        }
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2812
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2813
        if (__index == __minLen) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2814
            /* one of the operands has odd length - cannot continue short-wise */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2815
        } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2816
            if (__len1 > __len2) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2817
                while (__index < __len1) {
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2818
                    /* do not make this into one expression - ask cg why */
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2819
                    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2820
                    __diff -= __borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2821
                    if (__diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2822
                        __borrow = 0;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2823
                        ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2824
                        __index += 2;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2825
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2826
                        /* copy over rest */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2827
                        while (__index < __len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2828
                            ((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
  2829
                            __index+=2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2830
                        }
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2831
                        if (__index <= __len1) {
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2832
                            __resultDigits[__index-1] = __myDigits[__index-1];
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2833
                            __index++;
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2834
                        }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2835
                        break;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2836
                    }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2837
                    __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2838
                    /* __diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2839
                    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2840
                    __index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2841
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2842
            } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2843
                if (__len2 > __len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2844
                    while (__index < __len2) {
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2845
                        /* do not make this into one expression - ask cg why */
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2846
                        __diff = 0;
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2847
                        __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
  2848
                        __diff -= __borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2849
                        if (__diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2850
                            __borrow = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2851
                        } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2852
                            __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2853
                            /* __diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2854
                        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2855
                        ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2856
                        __index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2857
                    }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2858
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2859
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2860
        }
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  2861
#endif
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2862
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2863
         * subtract byte-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2864
         */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2865
        while (__index <= __minLen) {
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2866
            /* do not make this into one expression - ask cg why */
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2867
            __diff = __myDigits[__index-1];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2868
            __diff -= __otherDigits[__index-1];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2869
            __diff -= __borrow;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2870
            if (__diff >= 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2871
                __borrow = 0;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2872
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2873
                __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2874
                /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2875
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2876
            __resultDigits[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2877
            __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2878
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2879
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2880
        if (__len1 > __len2) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2881
            while (__index <= __len1) {
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2882
                /* do not make this into one expression - ask cg why */
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2883
                __diff = __myDigits[__index-1];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2884
                __diff -= __borrow;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2885
                if (__diff >= 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2886
                    __borrow = 0;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2887
                    /* copy over rest */
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2888
                    __resultDigits[__index-1] = __diff;
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2889
                    __index++;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2890
                    while (__index <= __len1) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2891
                        __resultDigits[__index-1] = __myDigits[__index-1];
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2892
                        __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2893
                    }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2894
                    break;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2895
                }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2896
                __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2897
                /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2898
                __resultDigits[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2899
                __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2900
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2901
        } else {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2902
            if (__len2 > __len1) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2903
                while (__index <= __len2) {
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2904
                    /* do not make this into one expression - ask cg why */
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2905
                    __diff = 0;
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2906
                    __diff -= __otherDigits[__index-1];
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2907
                    __diff -= __borrow;
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2908
                    if (__diff >= 0) {
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2909
                        __borrow = 0;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2910
                    } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2911
                        __borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  2912
                        /* __diff += 0x100; */
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2913
                    }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2914
                    __resultDigits[__index-1] = __diff;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2915
                    __index++;
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2916
                }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2917
            }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2918
        }
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2919
        borrow = __MKSMALLINT(__borrow);
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2920
        index = __MKSMALLINT(__index);
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2921
        lastDigit = __MKSMALLINT(__resultDigits[__intVal(lResult)-1]);
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2922
    }
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2923
%}.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2924
    ok == true ifFalse:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2925
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2926
        borrow := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2927
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2928
        done := false.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2929
        [done] whileFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2930
            diff := borrow.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2931
            (index <= len1) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2932
                diff := diff + (digitByteArray basicAt:index).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2933
                (index <= len2) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2934
                    diff := diff - (otherDigitByteArray basicAt:index)
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2935
                ]
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2936
            ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2937
                (index <= len2) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2938
                    diff := diff - (otherDigitByteArray basicAt:index)
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2939
                ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2940
                    "end reached"
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2941
                    done := true
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2942
                ]
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2943
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2944
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2945
            "/ workaround for
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2946
            "/ gcc code generator bug
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2947
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2948
            (diff >= 0) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2949
                borrow := 0
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2950
            ] ifFalse:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2951
                borrow := -1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2952
                diff := diff + 16r100
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2953
            ].
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2954
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2955
    "/        (diff < 0) ifTrue:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2956
    "/            borrow := -1.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2957
    "/            diff := diff + 16r100
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2958
    "/        ] ifFalse:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2959
    "/            borrow := 0
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2960
    "/        ].
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2961
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2962
            resultDigitByteArray basicAt:index put:diff.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2963
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2964
        ].
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2965
        lastDigit := resultDigitByteArray basicAt:lResult.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2966
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2967
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2968
    (borrow ~~ 0) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2969
        "/ must generate 255's complement
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2970
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2971
        result sign:-1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2972
        [index <= lResult] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2973
            resultDigitByteArray basicAt:index put:16rFF.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2974
            index := index + 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2975
        ].
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2976
        index := lResult.
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2977
        [index > 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2978
            resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2979
            index := index - 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2980
        ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2981
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2982
        index := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2983
        carry := 1.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2984
        [carry ~~ 0] whileTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2985
            (index <= lResult) ifTrue:[
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2986
                carry := (resultDigitByteArray basicAt:index) + carry.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2987
            ].
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2988
            resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2989
            carry := carry bitShift:-8.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2990
            index := index + 1
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2991
        ].
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2992
        lastDigit := resultDigitByteArray basicAt:lResult.
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2993
    ].
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2994
    (lastDigit ~~ 0 and:[lResult > SmallInteger maxBytes]) ifTrue:[
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2995
        ^ result
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2996
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2997
    ^ result compressed
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2998
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2999
    "Modified: 5.11.1996 / 14:09:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3000
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3001
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3002
absMod:anInteger
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3003
    "return a LargeIntegers representing
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3004
     abs(self) \\ abs(theArgument).
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3005
     Used as a helper for \\ and rem:"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3006
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3007
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3008
    |dividend divisor 
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3009
     shift "{ Class: SmallInteger }" |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3010
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3011
    anInteger == 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3012
        ^ DivisionByZeroSignal raiseRequest
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3013
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3014
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3015
    self = anInteger ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3016
        ^ 0
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3017
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3018
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3019
    shift := self highBit - anInteger highBit.
4140
3e66cfaae7a7 Some fixes for absMod: on a negative number
Stefan Vogel <sv@exept.de>
parents: 4139
diff changeset
  3020
    dividend := self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3021
    shift < 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3022
        ^ dividend.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3023
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3024
    shift == 0 ifTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3025
        divisor := anInteger simpleDeepCopy.
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3026
    ] ifFalse:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3027
        divisor := anInteger bitShift:shift.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3028
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3029
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3030
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3031
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3032
    [shift > 0] whileTrue:[
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3033
        (dividend absLess:divisor) ifFalse:[
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3034
            (dividend absSubtract: divisor) ifFalse:[ "result == 0"
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3035
                ^ dividend compressed            
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3036
            ].
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3037
        ].
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3038
        shift := shift - 1.
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3039
        divisor div2.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3040
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3041
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3042
    ^ dividend compressed
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3043
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3044
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3045
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absMod:4000000001] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3046
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absDivMod:4000000001] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3047
     16000000000 absMod:4000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3048
     16000000000 absMod:3000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3049
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3050
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3051
    "Modified: / 5.11.1996 / 18:40:24 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3052
    "Created: / 27.4.1999 / 19:45:44 / stefan"
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3053
    "Modified: / 26.7.1999 / 10:46:18 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3054
!
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3055
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3056
absMul:aLargeInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3057
    "return a LargeInteger representing abs(self) * abs(theArgument)"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3058
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3059
    |result otherDigitByteArray resultDigitByteArray ok
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3060
     idx      "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3061
     carry    "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3062
     len1     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3063
     len2     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3064
     dstIndex "{ Class: SmallInteger }"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3065
     prod     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3066
     v        "{ Class: SmallInteger }"|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3067
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3068
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3069
    otherDigitByteArray := aLargeInteger digitBytes.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3070
    len2 := otherDigitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3071
4151
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
  3072
    result := LargeInteger basicNew numberOfDigits:(len1 + len2).
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3073
    resultDigitByteArray := result digitBytes.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3074
    ok := false.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3075
%{
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  3076
    if (__isByteArray(__INST(digitByteArray))
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3077
     && __isByteArray(otherDigitByteArray)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3078
     && __isByteArray(resultDigitByteArray)
250
a5deb61ffdac *** empty log message ***
claus
parents: 175
diff changeset
  3079
     && __bothSmallInteger(len1, len2)) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3080
        unsigned char *myBytes = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3081
        unsigned char *otherBytes = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3082
        unsigned char *resultBytes = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3083
        unsigned char *_p1, *_p2, *_pResult, *_pResult0, *_pResult1, *_p1Last, *_p2Last;
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3084
        unsigned char *_pResultLast1;
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3085
        unsigned INT _v;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3086
        int _len1 = __intVal(len1);
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3087
        int _len2 = __intVal(len2);
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3088
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3089
        _p1Last = myBytes    + _len1 - 1;  /* the last byte */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3090
        _p2Last = otherBytes + _len2 - 1;  /* the last byte */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3091
        _pResult0 = resultBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3092
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3093
        /*
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3094
         *        aaa...aaa      f1[0] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3095
         *       bbb...bbb       f1[1] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3096
         *      ccc...ccc        f1[2] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3097
         *     ...
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3098
         *    xxx...xxx          f1[high] * f2
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3099
         *
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3100
         * start short-wise
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3101
         * bounds: (16rFFFF * 16rFFFF) + 16rFFFF -> FFFF0000
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3102
         */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3103
        _p1 = myBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3104
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3105
#if defined(alpha64)
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3106
        /* loop over ints of f1 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3107
        for (; _p1 < _p1Last-2; _p1 += 4, _pResult0 += 4) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3108
            unsigned INT word1 = ((unsigned int *)_p1)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3109
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3110
            _pResult = _pResult0;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3111
            _p2 = otherBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3112
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3113
            /* loop over ints of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3114
            while (_p2 < (_p2Last-2)) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3115
                _v = (word1 * ((unsigned int *)_p2)[0]) + ((unsigned int *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3116
                ((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3117
                _v >>= 32; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3118
                _pResult += 4;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3119
                if (_v) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3120
                    unsigned char *_pResultLast3;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3121
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3122
                    /* distribute carry - int-wise, then byte-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3123
                    _pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3124
                    for (_pResult1 = _pResult; _v; _pResult1 += 4) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3125
                        if (_pResult1 > _pResultLast3) break;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3126
                        _v += ((unsigned int *)_pResult1)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3127
                        ((unsigned int *)_pResult1)[0] = _v /* & 0xFFFFFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3128
                        _v >>= 32;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3129
                    }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3130
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3131
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3132
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3133
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3134
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3135
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3136
                _p2 += 4;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3137
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3138
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3139
            /* possible odd highByte of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3140
            while (_p2 <= _p2Last) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3141
                _v = (word1 * _p2[0]) + ((unsigned int *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3142
                ((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3143
                _v >>= 32; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3144
                _pResult += 4;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3145
                if (_v) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3146
                    unsigned char *_pResultLast3;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3147
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3148
                    /* distribute carry - int-wise, then byte-wise */
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3149
                    _pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3150
                    for (_pResult1 = _pResult; _v; _pResult1 += 4) {
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3151
                        if (_pResult1 > _pResultLast3) break;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3152
                        _v += ((unsigned int *)_pResult1)[0];
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3153
                        ((unsigned int *)_pResult1)[0] = _v /* & 0xFFFFFFFF */;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3154
                        _v >>= 32;
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3155
                    }
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  3156
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3157
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3158
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3159
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3160
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3161
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3162
                _p2++;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3163
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3164
        }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3165
#endif /* alpha64 */
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3166
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3167
        /* loop over shorts of f1 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3168
        for (; _p1 < _p1Last; _p1 += 2, _pResult0 += 2) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3169
            unsigned int short1 = ((unsigned short *)_p1)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3170
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3171
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3172
            short1 = ((short1 >> 8) & 0xFF) | ((short1 & 0xFF) << 8);
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3173
#endif
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3174
            _pResult = _pResult0;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3175
            _p2 = otherBytes;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3176
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3177
            /* loop over shorts of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3178
            while (_p2 < _p2Last) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3179
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3180
                unsigned int _short2;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3181
                unsigned int _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3182
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3183
                _short2 = ((unsigned short *)_p2)[0];
4268
506e49eb659b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4266
diff changeset
  3184
                _short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3185
                _short3 = ((unsigned short *)_pResult)[0];
4268
506e49eb659b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4266
diff changeset
  3186
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3187
                _v = (short1 * _short2) + _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3188
                _pResult[0] = _v;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3189
                _pResult[1] = _v >> 8;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3190
#else /* LSBFIRST */
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3191
                _v = (short1 * ((unsigned short *)_p2)[0]) + ((unsigned short *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3192
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3193
#endif
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3194
                _v >>= 16; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3195
                _pResult += 2;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3196
                if (_v) {
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3197
                    /* distribute carry - short-wise, then byte-wise */
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3198
                    _pResult1 = _pResult;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3199
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)  
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3200
                    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3201
                    for (; _v; _pResult1 += 2) {
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3202
                        if (_pResult1 > _pResultLast1) break;
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3203
                        _v += ((unsigned short *)_pResult1)[0];
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3204
                        ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3205
                        _v >>= 16;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3206
                    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3207
#endif
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3208
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3209
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3210
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3211
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3212
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3213
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3214
                _p2 += 2;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3215
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3216
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3217
            /* possible odd highByte of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3218
            if (_p2 <= _p2Last) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3219
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3220
                unsigned int _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3221
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3222
                _short3 = ((unsigned short *)_pResult)[0];
4268
506e49eb659b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4266
diff changeset
  3223
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3224
                _v = (short1 * _p2[0]) + _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3225
                _pResult[0] = _v;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3226
                _pResult[1] = _v >> 8;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3227
#else /* LSBFIRST */
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3228
                _v = (short1 * _p2[0]) + ((unsigned short *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3229
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3230
#endif
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3231
                _v >>= 16; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3232
                _pResult += 2;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3233
                if (_v) {
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3234
                    /* distribute carry - short-wise, then byte-wise */
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3235
                    _pResult1 = _pResult;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3236
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)  
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3237
                    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3238
                    for (; _v; _pResult1 += 2) {
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3239
                        if (_pResult1 > _pResultLast1) break;
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3240
                        _v += ((unsigned short *)_pResult1)[0];
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3241
                        ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3242
                        _v >>= 16;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3243
                    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3244
#endif
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3245
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3246
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3247
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3248
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3249
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3250
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3251
                _p2++;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3252
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3253
        }
4164
59da946fb307 oops - the short-multiply optimization is only ok
Claus Gittinger <cg@exept.de>
parents: 4163
diff changeset
  3254
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3255
        /* possible odd highByte of f1 (or byteLoop, if not LSBFIRST) */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3256
        for (; _p1 <= _p1Last; _p1++, _pResult0++) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3257
            unsigned int byte1 = _p1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3258
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3259
            _pResult = _pResult0;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3260
            _p2 = otherBytes;
4175
ecbeb3109903 fixed absMul: (for non-LSBFIRST)
Claus Gittinger <cg@exept.de>
parents: 4174
diff changeset
  3261
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3262
            /* loop over shorts of f2 */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3263
            while (_p2 < _p2Last) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3264
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3265
                unsigned int _short2;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3266
                unsigned int _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3267
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3268
                _short2 = ((unsigned short *)_p2)[0];
4268
506e49eb659b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4266
diff changeset
  3269
                _short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3270
                _short3 = ((unsigned short *)_pResult)[0];
4268
506e49eb659b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4266
diff changeset
  3271
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3272
                _v = (byte1 * _short2) + _short3;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3273
                _pResult[0] = _v;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3274
                _pResult[1] = _v >> 8;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3275
#else /* LSBFIRST */
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3276
                _v = (byte1 * ((unsigned short *)_p2)[0]) + ((unsigned short *)_pResult)[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3277
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3278
#endif
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3279
                _v >>= 16; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3280
                _pResult += 2;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3281
                if (_v) {
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3282
                    /* distribute carry - short-wise, then byte-wise */
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3283
                    _pResult1 = _pResult;
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3284
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3285
                    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3286
                    for (_pResult1 = _pResult; _v; _pResult1 += 2) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3287
                        if (_pResult1 > _pResultLast1) break;
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3288
                        _v += ((unsigned short *)_pResult1)[0];
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3289
                        ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3290
                        _v >>= 16;
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3291
                    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3292
#endif /* __LSBFIRST */
4261
2e2697a523f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4260
diff changeset
  3293
                    for (; _v; _pResult1++) {
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3294
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3295
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3296
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3297
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3298
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3299
                _p2 += 2;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3300
            }
4164
59da946fb307 oops - the short-multiply optimization is only ok
Claus Gittinger <cg@exept.de>
parents: 4163
diff changeset
  3301
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3302
            /* possible odd highByte of f2 (or byteLoop, if not LSBFIRST) */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3303
            while (_p2 <= _p2Last) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3304
                _v = (byte1 * _p2[0]) + _pResult[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3305
                _pResult[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3306
                _v >>= 8; /* now _v contains the carry*/
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3307
                _pResult++;                
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3308
                if (_v) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3309
                    /* distribute carry */
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3310
                    for (_pResult1 = _pResult; _v; _pResult1++) {
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3311
                        _v += _pResult1[0];
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3312
                        _pResult1[0] = _v /* & 0xFF */;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3313
                        _v >>= 8;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3314
                    }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3315
                }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3316
                _p2++;
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3317
            }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3318
        }
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3319
        ok = true;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3320
    }
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3321
%}.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3322
    ok ifFalse:[
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3323
        1 to:len1 do:[:index1 |
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3324
            1 to:len2 do:[:index2 |
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3325
                dstIndex := index1 + index2 - 1.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3326
                prod := (digitByteArray basicAt:index1) * (otherDigitByteArray basicAt:index2).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3327
                prod := prod + (resultDigitByteArray basicAt:dstIndex).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3328
                resultDigitByteArray basicAt:dstIndex put:(prod bitAnd:16rFF).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3329
                carry := prod bitShift:-8.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3330
                carry ~~ 0 ifTrue:[
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3331
                    idx := dstIndex + 1.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3332
                    [carry ~~ 0] whileTrue:[
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3333
                        v := (resultDigitByteArray basicAt:idx) + carry.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3334
                        resultDigitByteArray basicAt:idx put:(v bitAnd:255).
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3335
                        carry := v bitShift:-8.
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3336
                        idx := idx + 1
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3337
                    ]
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3338
                ]
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3339
            ]
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3340
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3341
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3342
    ^ result compressed
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3343
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3344
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3345
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
  3346
    "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
  3347
     with sign: newSign.
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3348
     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
  3349
     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
  3350
     This is a helper for addition and subtraction - not for public use."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3351
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3352
    |result done otherDigitByteArray resultDigitByteArray
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3353
     len1   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3354
     len2   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3355
     newLen "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3356
     index  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3357
     carry  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3358
     sum    "{ Class: SmallInteger }" |
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3359
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3360
    otherDigitByteArray := aLargeInteger digitBytes.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3361
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3362
%{
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3363
    OBJ _digitByteArray = __INST(digitByteArray);
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3364
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3365
    if (__isByteArray(_digitByteArray)
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3366
     && __isByteArray(otherDigitByteArray)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3367
        int _len1, _len2, _newLen;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3368
        unsigned char *_myDigits, *_otherDigits, *_newDigits;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3369
        int _index, _carry;
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3370
        int _comLen;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3371
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3372
        _len1 = __byteArraySize(_digitByteArray);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3373
        _len2 = __byteArraySize(otherDigitByteArray);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3374
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3375
        _otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3376
        _myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3377
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3378
        if (_len1 < _len2) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3379
            _comLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3380
            _newLen = _len2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3381
            if (_otherDigits[_len2 - 1] == 0xFF) _newLen++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3382
        } else if (_len2 < _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3383
            _comLen = _len2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3384
            _newLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3385
            if (_myDigits[_len1 - 1] == 0xFF) _newLen++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3386
        } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3387
            /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3388
             * there can only be an overflow from the high bytes,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3389
             * if their sum is >= 255
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3390
             * (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
  3391
             */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3392
            _newLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3393
            if ((_otherDigits[_len2 - 1] + _myDigits[_len1 - 1]) >= 0xFF) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3394
                _newLen++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3395
            } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3396
                if (_newLen == sizeof(INT)) {
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3397
                    OBJ _uint;
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3398
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3399
                    /* 
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3400
                     * two word-sized numbers, no carry - a very common case ...
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3401
                     */
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3402
#if defined(__LSB_FIRST) || defined(i386) || defined(alpha)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3403
                    unsigned INT _sum = *(unsigned INT *)_otherDigits + *(unsigned INT *)_myDigits;
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3404
#else
5002
e895e251d501 __longIntVal has been renamed to __unsignedLongIntVal
Stefan Vogel <sv@exept.de>
parents: 5000
diff changeset
  3405
                    unsigned INT _sum = __unsignedLongIntVal(self) + __unsignedLongIntVal(aLargeInteger);
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3406
#endif /* not LSB_FIRST */
5008
1a19e0059c54 Complete prev fix.
Stefan Vogel <sv@exept.de>
parents: 5002
diff changeset
  3407
                    if (_sum <= _MAX_INT) {
1a19e0059c54 Complete prev fix.
Stefan Vogel <sv@exept.de>
parents: 5002
diff changeset
  3408
                        _uint = __MKSMALLINT(_sum * __intVal(newSign));
1a19e0059c54 Complete prev fix.
Stefan Vogel <sv@exept.de>
parents: 5002
diff changeset
  3409
                    } else {
1a19e0059c54 Complete prev fix.
Stefan Vogel <sv@exept.de>
parents: 5002
diff changeset
  3410
                        _uint = __MKULARGEINT(_sum);
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3411
                        __LargeIntegerInstPtr(_uint)->l_sign = newSign;
5008
1a19e0059c54 Complete prev fix.
Stefan Vogel <sv@exept.de>
parents: 5002
diff changeset
  3412
                    }
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3413
                    RETURN (_uint);
4215
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
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3416
            _comLen = _len1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3417
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3418
        resultDigitByteArray = __BYTEARRAY_UNINITIALIZED_NEW_INT(_newLen);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3419
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3420
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3421
         * must refetch - GC could have been invoked
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3422
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3423
        _digitByteArray = __INST(digitByteArray);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3424
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3425
        _myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3426
        _otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3427
        _newDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3428
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3429
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3430
         * add them ...
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3431
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3432
        _index = 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3433
        _carry = 0;
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3434
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3435
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3436
# if 0 && defined(alpha64) && defined(__GNUC__)
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3437
        {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3438
            int _comLen7;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3439
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3440
            /*
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3441
             * have a 64bit integers;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3442
             * add quad-wise
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3443
             * accessing bytes at: [index-1][index][index+1]..[index+6]
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3444
             */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3445
            _comLen7 = _comLen - 3 - 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3446
            while (_index <= _comLen7) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3447
                UINT64 _sum, _t1, _t2;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3448
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3449
                asm ("addq   %5,%6,%1         \n     /* sum */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3450
                      addq   %0,%1,%1         \n     /* plus carryIn */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3451
                      cmpult %1,%5,%2         \n     /* was there a carry ? */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3452
                      cmpult %1,%6,%3         \n     /* was there a carry ? */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3453
                      bis    %2,%3,%0         \n     /* carryOut */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3454
                     "    
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3455
                        : "=r"  (_carry),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3456
                          "=r"  (_sum),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3457
                          "r"   (_t1),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3458
                          "r"   (_t2)
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3459
                        : "r"   (_carry),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3460
                          "r"   (((unsigned long *)(&(_myDigits[_index - 1])))[0]), 
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3461
                          "r"   (((unsigned long *)(&(_otherDigits[_index - 1])))[0])
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3462
                    );
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3463
                /* _sum = _sum & 0xFFFFFFFF; */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3464
                ((unsigned long *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3465
                _index += 8;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3466
            }
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3467
        }
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3468
# endif /* alpha64 */
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3469
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
  3470
# if 0 && defined(alpha64)      /* not faster */
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3471
        {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3472
            int _comLen7;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3473
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3474
            /*
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3475
             * have a 64bit integers;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3476
             * add quad-wise
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3477
             * accessing bytes at: [index-1][index][index+1]..[index+6]
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3478
             */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3479
            _comLen7 = _comLen - 3 - 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3480
            while (_index <= _comLen7) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3481
                UINT64 _sum, _t1, _t2;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3482
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3483
                _t1 = ((UINT64 *)(&(_myDigits[_index - 1])))[0];
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3484
                _t2 = ((UINT64 *)(&(_otherDigits[_index - 1])))[0];
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3485
                _sum = _t1 + _t2 + _carry;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3486
                ((UINT64 *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3487
                _carry = (_sum < _t1) | (_sum < _t2);
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3488
                _index += 8;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3489
            }
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3490
        }
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3491
# endif /* alpha64 */
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3492
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3493
# ifdef UINT64
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3494
        {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3495
            int _comLen3;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3496
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3497
            /*
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3498
             * have a 64bit integer type;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3499
             * add int-wise
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3500
             * accessing bytes at: [index-1][index][index+1][index+2]
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3501
             */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3502
            _comLen3 = _comLen - 3;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3503
            while (_index <= _comLen3) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3504
                UINT64 _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3505
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3506
                _sum = _carry
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3507
                        + *(unsigned *)(&(_myDigits[_index - 1]))
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3508
                        + *(unsigned *)(&(_otherDigits[_index - 1]));
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3509
                _carry = _sum >> 32;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3510
                /* _sum = _sum & 0xFFFFFFFF; */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3511
                ((unsigned int *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3512
                _index += 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3513
            }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3514
        }
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3515
# else
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3516
#  if defined(i386) && defined(__GNUC__)
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3517
        {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3518
            int _comLen3;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3519
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3520
            _comLen3 = _comLen - 3 - 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3521
            while (_index <= _comLen3) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3522
                unsigned int _sum, _sum2;
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3523
                unsigned int __in1A, __in1B, __in2A, __in2B;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3524
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3525
                __in1A = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3526
                __in2A = ((unsigned int *)(&(_myDigits[_index - 1])))[1];
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3527
                __in1B = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3528
                __in2B = ((unsigned int *)(&(_otherDigits[_index - 1])))[1];
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3529
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3530
                asm ("addl %%edx,%%eax         
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3531
                      movl $0,%%edx            
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3532
                      adcl $0,%%edx            
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3533
                      addl %5,%%eax            
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3534
                      adcl $0,%%edx
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3535
4283
cb0eee96df13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4282
diff changeset
  3536
                      addl %%edx,%%ecx  
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3537
                      movl $0,%%edx            
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3538
                      adcl $0,%%edx            
4283
cb0eee96df13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4282
diff changeset
  3539
                      addl %7,%%ecx            
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3540
                      adcl $0,%%edx
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3541
                     "    
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3542
                        : "=d"  (_carry),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3543
                          "=a"  (_sum),
4283
cb0eee96df13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4282
diff changeset
  3544
                          "=c"  (_sum2)
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3545
                        : "0"   (_carry),
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3546
                          "1"   (__in1A), 
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3547
                          "rm"  (__in1B), 
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3548
                          "2"   (__in2A), 
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3549
                          "rm"  (__in2B) 
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3550
                    );
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3551
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3552
                ((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3553
                ((unsigned *)(&(_newDigits[_index - 1])))[1] = _sum2;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3554
                _index += 8;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3555
            }
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3556
            /*
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3557
             * add int-wise
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3558
             * accessing bytes at: [index-1][index][index+1][index+2]
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3559
             */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3560
            _comLen3 = _comLen3 + 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3561
            if (_index <= _comLen3) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3562
                unsigned int _sum;
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3563
                unsigned int __inA, __inB;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3564
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3565
                __inA = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3566
                __inB = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3567
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3568
                asm ("addl %%edx,%%eax      \n   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3569
                      movl $0,%%edx         \n   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3570
                      adcl $0,%%edx         \n   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3571
                      addl %4,%%eax         \n   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3572
                      adcl $0,%%edx"    
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3573
                        : "=d"  (_carry),
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3574
                          "=a"  (_sum)
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3575
                        : "0"   (_carry),
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3576
                          "1"   (__inA), 
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  3577
                          "rm"  (__inB) 
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3578
                    );
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3579
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3580
                ((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3581
                _index += 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3582
            }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3583
        }
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3584
#  endif /* i386 && GNUC */
4276
e521248cbb88 tuned large + large on win32
Claus Gittinger <cg@exept.de>
parents: 4270
diff changeset
  3585
#  if defined(i386) && defined(WIN32)
4282
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3586
        {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3587
            int _comLen3;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3588
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3589
            /*
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3590
             * add long-wise
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3591
             * accessing bytes at: [index-1][index][index+1][index+2]
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3592
             */
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3593
            _comLen3 = _comLen - 3;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3594
            while (_index <= _comLen3) {
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3595
                unsigned int _sum, _v1, _v2;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3596
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3597
                _v1 = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3598
                _v2 = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3599
                asm { 
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3600
                      mov eax, _v1   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3601
                      add eax, _v2   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3602
                      mov edx, 0
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3603
                      adc edx, 0
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3604
                      add eax, _carry   
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3605
                      adc edx, 0
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3606
                      mov _carry, edx
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3607
                      mov _sum, eax
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3608
                    }
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3609
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3610
                ((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3611
                _index += 4;
fc1a9c630c92 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4281
diff changeset
  3612
            }
4276
e521248cbb88 tuned large + large on win32
Claus Gittinger <cg@exept.de>
parents: 4270
diff changeset
  3613
        }
e521248cbb88 tuned large + large on win32
Claus Gittinger <cg@exept.de>
parents: 4270
diff changeset
  3614
#  endif /* i386 && WIN32 */
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3615
# endif / INT64 */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3616
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3617
         * add short-wise
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3618
         * accessing bytes at: [index-1][index]
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3619
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3620
        while (_index < _comLen) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3621
            unsigned int _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3622
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3623
            _sum = _carry 
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3624
                   + ((unsigned short *)(&(_myDigits[_index - 1])))[0]
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3625
                   + ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3626
            _carry = _sum >> 16;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3627
            /* _sum = _sum & 0xFFFF; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3628
            *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3629
            _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3630
        }
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3631
#else
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3632
# ifdef sparc
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3633
        /*
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3634
         * add short-wise
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3635
         * accessing bytes at: [index-1][index]
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3636
         */
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3637
        while (_index < _comLen) {
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3638
            unsigned int _sum;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3639
            unsigned short _v1, _v2;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3640
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3641
            _v1 = ((unsigned short *)(&(_myDigits[_index - 1])))[0];
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3642
            _v2 = ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3643
            _sum = _carry + (_v1>>8) + (_v2>>8);
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3644
            _carry = _sum >> 8;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3645
            _newDigits[_index - 1] = _sum;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3646
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3647
            _sum = _carry + (_v1 & 0xFF) + (_v2 & 0xFF);
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3648
            _carry = _sum >> 8;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3649
            _newDigits[_index] = _sum;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3650
            _index += 2;
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3651
        }
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3652
# endif
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
  3653
#endif /* __LSBFIRST */
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  3654
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3655
        /*
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3656
         * add byte-wise
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3657
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3658
        while (_index <= _comLen) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3659
            unsigned int _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3660
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3661
            _sum = _carry 
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3662
                   + _myDigits[_index - 1] 
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3663
                   + _otherDigits[_index - 1];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3664
            _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3665
            /* _sum = _sum & 0xFF; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3666
            _newDigits[_index - 1] = _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3667
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3668
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3669
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3670
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3671
         * rest
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3672
         */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3673
        if (_len1 > _len2) {
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3674
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3675
            if (_index <= _len1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3676
                if ((_index - 1) & 1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3677
                    /* odd byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3678
                    unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3679
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3680
                    _sum = _carry + _myDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3681
                    _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3682
                    /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3683
                    _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3684
                    _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3685
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3686
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3687
                while (_index < _len1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3688
                    /* shorts */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3689
                    unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3690
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3691
                    _sum = _carry + *(unsigned short *)(&(_myDigits[_index - 1]));
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3692
                    _carry = _sum >> 16;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3693
                    /* _sum = _sum & 0xFFFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3694
                    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3695
                    _index += 2;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3696
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3697
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3698
                if (_index <= _len1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3699
                    /* last byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3700
                    unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3701
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3702
                    _sum = _carry + _myDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3703
                    _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3704
                    /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3705
                    _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3706
                    _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3707
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3708
            }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3709
#else
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3710
            while (_index <= _len1) {
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3711
                unsigned int _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3712
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3713
                _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
  3714
                _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3715
                /* _sum = _sum & 0xFF; */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3716
                _newDigits[_index - 1] = _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3717
                _index++;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3718
            }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3719
#endif /* not LSB */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3720
        } else {
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3721
            if (_len2 > _len1) {
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3722
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3723
                if (_index <= _len2) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3724
                    if ((_index - 1) & 1) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3725
                        /* odd byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3726
                        unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3727
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3728
                        _sum = _carry + _otherDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3729
                        _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3730
                        /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3731
                        _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3732
                        _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3733
                    }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3734
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3735
                    while (_index < _len2) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3736
                        /* shorts */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3737
                        unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3738
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3739
                        _sum = _carry + *(unsigned short *)(&(_otherDigits[_index - 1]));
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3740
                        _carry = _sum >> 16;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3741
                        /* _sum = _sum & 0xFFFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3742
                        *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3743
                        _index += 2;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3744
                    }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3745
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3746
                    if (_index <= _len2) {
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3747
                        /* last byte */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3748
                        unsigned int _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3749
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3750
                        _sum = _carry + _otherDigits[_index - 1];
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3751
                        _carry = _sum >> 8;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3752
                        /* _sum = _sum & 0xFF; */
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3753
                        _newDigits[_index - 1] = _sum;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3754
                        _index++;
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3755
                    }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3756
                }
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3757
#else
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3758
                while (_index <= _len2) {
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3759
                    unsigned int _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3760
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3761
                    _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
  3762
                    _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3763
                    /* _sum = _sum & 0xFF; */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3764
                    _newDigits[_index - 1] = _sum;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3765
                    _index++;
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3766
                }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3767
#endif /* not LSB */
4229
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3768
            }
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3769
        }
7956ab97154f speedup adding a large-largeInt with a small-largeInt
Claus Gittinger <cg@exept.de>
parents: 4222
diff changeset
  3770
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3771
        while (_index <= _newLen) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3772
            unsigned int _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3773
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3774
            _sum = _carry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3775
            _carry = _sum >> 8;
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3776
            /* _sum = _sum & 0xFF; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3777
            _newDigits[_index - 1] = _sum;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3778
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3779
        }
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3780
    }
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3781
%}.
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3782
    resultDigitByteArray notNil ifTrue:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3783
        result := self class basicNew.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3784
        result setDigits:resultDigitByteArray.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3785
        result sign:newSign.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3786
    ] ifFalse:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3787
        len1 := digitByteArray size.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3788
        len2 := otherDigitByteArray size.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3789
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3790
        "/ earlier versions estimated the newLength as:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3791
        "/ (len1 max:len2) + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3792
        "/ and reduced the result.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3793
        "/ however, if one of the addends is smaller,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3794
        "/ the result will never require another digit,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3795
        "/ if the highest digit of the larger addent is
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3796
        "/ not equal to 255. Therefore, in most cases,
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3797
        "/ we can avoid the computation and resizing 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3798
        "/ in #reduced.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3799
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3800
        len1 < len2 ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3801
            newLen := len2.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3802
            (otherDigitByteArray at:len2) == 16rFF ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3803
                newLen := newLen + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3804
            ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3805
        ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3806
            len2 < len1 ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3807
                newLen := len1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3808
                (digitByteArray at:len1) == 16rFF ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3809
                    newLen := newLen + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3810
                ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3811
            ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3812
                newLen := len1 + 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3813
            ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3814
        ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3815
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3816
        result := self class basicNew numberOfDigits:newLen.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3817
        result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3818
        resultDigitByteArray := result digitBytes.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3819
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3820
        index := 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3821
        carry := 0.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3822
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3823
        done := false.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3824
        [done] whileFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3825
            sum := carry.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3826
            (index <= len1) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3827
                sum := sum + (digitByteArray basicAt:index).
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3828
                (index <= len2) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3829
                    sum := sum + (otherDigitByteArray basicAt:index)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3830
                ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3831
            ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3832
                (index <= len2) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3833
                    sum := sum + (otherDigitByteArray basicAt:index)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3834
                ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3835
                    "end reached"
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3836
                    done := true
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3837
                ]
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3838
            ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3839
            (sum >= 16r100) ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3840
                carry := 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3841
                sum := sum - 16r100
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3842
            ] ifFalse:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3843
                carry := 0
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3844
            ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3845
            resultDigitByteArray basicAt:index put:sum.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3846
            index := index + 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3847
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3848
    ].
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3849
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3850
    ^ result compressed
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3851
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3852
    "Modified: 11.8.1997 / 03:23:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3853
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3854
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3855
absSubtract:aLargeInteger
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3856
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3857
        destructively subtract aLargeInteger from myself
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3858
        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
  3859
        (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
  3860
         on the receiver)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3861
        Only allowed for positive receiver and argument
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3862
        The receiver must be >= the argument.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3863
        The receiver must be a temporary scratch-number"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3864
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3865
    |otherDigitByteArray
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3866
     len1   "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3867
     len2   "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3868
     index  "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3869
     borrow "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3870
     diff   "{ Class: SmallInteger }"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3871
     notZero
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3872
    |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3873
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3874
    notZero := false.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3875
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3876
    otherDigitByteArray := aLargeInteger digitBytes.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3877
    len2 := otherDigitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3878
    len2 > len1 ifTrue:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3879
        [(otherDigitByteArray at:len2) == 0] whileTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3880
            len2 := len2 - 1
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3881
        ].
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3882
        len2 > len1 ifTrue:[
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3883
            self halt "/ may not be called that way
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3884
        ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3885
    ].
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3886
    "/ knowing that len2 is <= len1
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3887
%{
4189
Claus Gittinger <cg@exept.de>
parents: 4188
diff changeset
  3888
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3889
    OBJ _digitByteArray = __INST(digitByteArray);
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3890
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3891
    if (__isByteArray(_digitByteArray)
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  3892
     && __isByteArray(otherDigitByteArray)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3893
        int _len1 = __intVal(len1), 
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3894
            _len2 = __intVal(len2);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3895
        unsigned char *_myDigits, *_otherDigits;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3896
        int _index = 1, _borrow = 0;
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3897
        INT _diff;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3898
        INT anyBitNonZero = 0;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3899
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3900
        _otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3901
        _myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3902
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3903
#if defined(alpha64)
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3904
        {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3905
            int _len2Q;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3906
            /*
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3907
             * subtract int-wise
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3908
             */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3909
            _len2Q = _len2-2;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3910
            while (_index < _len2Q) {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3911
                /* do not combine the expression below (may lead to unsigned result on some machines */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3912
                _diff = ((unsigned int *)(_myDigits+_index-1))[0];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3913
                _diff -= ((unsigned int *)(_otherDigits+_index-1))[0];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3914
                _diff -= _borrow;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3915
                if (_diff >= 0) {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3916
                    _borrow = 0;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3917
                } else {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3918
                    _borrow = 1;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3919
                    /* _diff += 0x10000; */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3920
                }
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3921
                ((unsigned int *)(_myDigits+_index-1))[0] = _diff;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3922
                anyBitNonZero |= (_diff & 0xFFFFFFFFL);
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3923
                _index += 4;
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3924
            }
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3925
        }
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3926
#endif
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3927
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3928
#if defined(i386) || defined(__LSBFIRST)
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3929
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3930
         * subtract short-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3931
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3932
        while (_index < _len2) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3933
            /* do not combine the expression below (may lead to unsigned result on some machines */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3934
            _diff = ((unsigned short *)(_myDigits+_index-1))[0];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3935
            _diff -= ((unsigned short *)(_otherDigits+_index-1))[0];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3936
            _diff -= _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3937
            if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3938
                _borrow = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3939
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3940
                _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3941
                /* _diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3942
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3943
            ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3944
            anyBitNonZero |= (_diff & 0xFFFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3945
            _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3946
        }
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3947
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3948
        if (_index <= _len2) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3949
            /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3950
             * cannot continue with shorts - there is an odd number of
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3951
             * bytes in the minuent
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3952
             */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3953
        } else {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3954
            while (_index < _len1) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3955
                /* do not combine the expression below (may lead to unsigned result on some machines */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3956
                _diff = ((unsigned short *)(_myDigits+_index-1))[0];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3957
                _diff -= _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3958
                if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3959
                    /* _borrow = 0; */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3960
                    ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3961
                    anyBitNonZero |= (_diff & 0xFFFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3962
                    _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3963
                    while (_index < _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3964
                        anyBitNonZero |= ((unsigned short *)(_myDigits+_index-1))[0];
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3965
                        if (anyBitNonZero) {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3966
                            RETURN (true);
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3967
                        }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3968
                        _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3969
                    }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3970
                    /* last odd index */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3971
                    if (_index <= _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3972
                        anyBitNonZero |= _myDigits[_index - 1];;
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3973
                        if (anyBitNonZero) {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3974
                            RETURN (true);
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3975
                        }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3976
                        _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3977
                    }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3978
                    RETURN (anyBitNonZero ? true : false);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3979
                }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3980
                _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  3981
                /* _diff += 0x10000; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3982
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3983
                ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3984
                anyBitNonZero |= (_diff & 0xFFFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3985
                _index += 2;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3986
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3987
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3988
#endif
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3989
        /*
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3990
         * subtract byte-wise
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3991
         */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3992
        while (_index <= _len2) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3993
            /* do not combine the expression below (may lead to unsigned result on some machines */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3994
            _diff = _myDigits[_index - 1];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3995
            _diff -= _otherDigits[_index - 1];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  3996
            _diff -= _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3997
            if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3998
                _borrow = 0;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3999
            } else {
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  4000
                _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  4001
                /* _diff += 0x100; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4002
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4003
            _myDigits[_index - 1] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4004
            anyBitNonZero |= (_diff & 0xFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4005
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4006
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4007
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4008
        while (_index <= _len1) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4009
            /* do not combine the expression below (may lead to unsigned result on some machines */
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4010
            _diff = _myDigits[_index - 1];
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4011
            _diff -= _borrow;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4012
            if (_diff >= 0) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4013
                /* _borrow = 0; */
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4014
                _myDigits[_index - 1] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4015
                anyBitNonZero |= (_diff & 0xFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4016
                _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4017
                while (_index <= _len1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4018
                    anyBitNonZero |= _myDigits[_index - 1];
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4019
                    if (anyBitNonZero) {
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4020
                        RETURN (true);
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4021
                    }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4022
                    _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4023
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4024
                break;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4025
            }
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  4026
            _borrow = 1;
4254
3846b94301b8 another subtract bug (sigh)
Claus Gittinger <cg@exept.de>
parents: 4252
diff changeset
  4027
            /* _diff += 0x100; */
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4028
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4029
            _myDigits[_index - 1] = _diff;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4030
            anyBitNonZero |= (_diff & 0xFF);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4031
            _index++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4032
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4033
        RETURN (anyBitNonZero ? true : false);
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4034
    }
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4035
%}.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4036
    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
  4037
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4038
"/    index := 1.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4039
"/    borrow := 0.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4040
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4041
"/    [index <= len1] whileTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4042
"/        diff := borrow.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4043
"/        diff := diff + (digitByteArray basicAt:index).
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4044
"/        index <= len2 ifTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4045
"/            diff := diff - (otherDigitByteArray basicAt:index).
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4046
"/        ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4047
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4048
"/        "/ workaround for
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4049
"/        "/ gcc code generator bug
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4050
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4051
"/        (diff >= 0) ifTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4052
"/            borrow := 0
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4053
"/        ] ifFalse:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4054
"/            borrow := -1.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4055
"/            diff := diff + 16r100
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4056
"/        ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4057
"/        diff ~~ 0 ifTrue:[
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4058
"/            notZero := true
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4059
"/        ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4060
"/        digitByteArray basicAt:index put:diff.
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4061
"/        index := index + 1
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4062
"/    ].
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4063
"/
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4064
"/    ^ notZero
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4065
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4066
    "Created: / 5.11.1996 / 16:23:47 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4067
    "Modified: / 5.11.1996 / 18:56:50 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4068
    "Modified: / 27.4.1999 / 18:08:23 / stefan"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4069
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4070
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4071
div2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4072
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4073
       destructively divide the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4074
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4075
%{  /* NOCONTEXT */
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4076
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4077
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4078
    if (__isByteArray(__digits)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4079
        int __nBytes = __byteArraySize(__digits);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4080
        unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4081
        unsigned INT __this, __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4082
        int __idx;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4083
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4084
        if (__nBytes == 1) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4085
            __bp[0] >>= 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4086
            RETURN (self);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4087
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4088
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4089
        __idx = 1;
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4090
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4091
#if defined(alpha64)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4092
        if (sizeof(unsigned INT) == 8) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4093
            int __endIndex = __nBytes - 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4094
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4095
            if (__idx < __endIndex) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4096
                __this = ((unsigned INT *)__bp)[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4097
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4098
                while (__idx < __endIndex) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4099
                    __next = ((unsigned INT *)__bp)[1];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4100
                    __this = (__this >> 1) /* & 0x7FFFFFFFFFFFFFF */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4101
                    __this |= __next << 63;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4102
                    ((unsigned INT *)__bp)[0] = __this;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4103
                    __this = __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4104
                    __bp += 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4105
                    __idx += 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4106
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4107
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4108
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4109
#else
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4110
# if defined(__LSBFIRST) || defined(i386) 
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4111
        if (sizeof(unsigned int) == 4) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4112
            int __endIndex = __nBytes - 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4113
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4114
            if (__idx < __endIndex) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4115
                __this = ((unsigned INT *)__bp)[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4116
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4117
                while (__idx < __endIndex) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4118
                    __next = ((unsigned int *)__bp)[1];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4119
                    __this = (__this >> 1) /* & 0x7FFFFFF */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4120
                    __this |= __next << 31;
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4121
                    ((unsigned int *)__bp)[0] = __this;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4122
                    __this = __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4123
                    __bp += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4124
                    __idx += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4125
                }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4126
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4127
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4128
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  4129
#endif
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4130
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4131
        __this = __bp[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4132
        while (__idx < __nBytes) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4133
            __next = __bp[1];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4134
            __this >>= 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4135
            __this |= __next << 7;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4136
            __bp[0] = __this;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4137
            __this = __next;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4138
            __bp++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4139
            __idx++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4140
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4141
        __bp[0] = __this >> 1;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4142
        RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4143
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4144
%}.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4145
    self primitiveFailed
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4146
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4147
    "
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4148
     100000 asLargeInteger div2      
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4149
     1000000000000000000000000000 div2 
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4150
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4151
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4152
    "Modified: 5.11.1996 / 16:12:56 / cg"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4153
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4154
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4155
mul2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4156
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4157
       destructively multiply the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4158
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4159
    |nBytes "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4160
     b      "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4161
     t|
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4162
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4163
    nBytes := digitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4164
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4165
    b := digitByteArray at:nBytes.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4166
    (b bitAnd:16r80) ~~ 0 ifTrue:[
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4167
        "/ need another byte
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4168
        nBytes := nBytes + 1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4169
        t := ByteArray uninitializedNew:nBytes.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4170
        t replaceFrom:1 to:nBytes-1 with:digitByteArray startingAt:1.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4171
        t at:nBytes put:0.
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4172
        digitByteArray := t.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4173
    ].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4174
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4175
%{
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4176
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4177
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4178
    if (__isByteArray(__digits)) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4179
        int __nBytes = __intVal(nBytes);
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4180
        unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4181
        unsigned INT __carry = 0, __newCarry,  __this;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4182
        int __idx;
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4183
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4184
#if defined(alpha64)
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4185
        if (sizeof(unsigned INT) == 8) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4186
            while (__nBytes >= 8) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4187
                __this = ((unsigned INT *)__bp)[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4188
                __newCarry = (__this >> 63) /* & 1 */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4189
                ((unsigned INT *)__bp)[0] = (__this << 1) | __carry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4190
                __carry = __newCarry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4191
                __bp += 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4192
                __nBytes -= 8;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4193
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4194
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4195
#else
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4196
# if defined(__LSBFIRST) || defined(i386) /* XXX actually: LSB_FIRST */
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4197
        if (sizeof(unsigned int) == 4) {
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4198
            while (__nBytes >= 4) {
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4199
                __this = ((unsigned int *)__bp)[0];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4200
                __newCarry = (__this >> 31) /* & 1 */;
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4201
                ((unsigned int *)__bp)[0] = (__this << 1) | __carry;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4202
                __carry = __newCarry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4203
                __bp += 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4204
                __nBytes -= 4;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4205
            }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4206
        }
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4207
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  4208
#endif
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4209
        while (__nBytes) {
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4210
            __this = __bp[0];
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4211
            __newCarry = (__this >> 7) /* & 1 */;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4212
            __bp[0] = (__this << 1) | __carry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4213
            __carry = __newCarry;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4214
            __bp++;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4215
            __nBytes--;
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4216
        }
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4217
        RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4218
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4219
%}.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4220
    self primitiveFailed
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4221
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4222
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4223
     100000 asLargeInteger mul2 
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4224
     10000000000000000000000000000 mul2 
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4225
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4226
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4227
    "Modified: 5.11.1996 / 16:37:32 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4228
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4229
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4230
mul256
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4231
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4232
       destructively multiply the receiver by 256."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4233
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4234
    |newDigits newSize|
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4235
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4236
    newSize := digitByteArray size + 1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4237
    newDigits := ByteArray uninitializedNew:newSize.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4238
"/    newDigits replaceFrom:2 with:digitByteArray startingAt:1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4239
    newDigits replaceBytesFrom:2 to:newSize with:digitByteArray startingAt:1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4240
    newDigits at:1 put:0.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4241
    digitByteArray := newDigits
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4242
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4243
    "Modified: / 20.5.1999 / 09:16:42 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4244
!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4245
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4246
numberOfDigits:nDigits
2001
8c2b957f0cb3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
  4247
"/    digitByteArray := ByteArray uninitializedNew:nDigits.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4248
    digitByteArray := ByteArray new:nDigits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4249
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4250
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4251
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4252
setDigits:digits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4253
    digitByteArray := digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4254
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4255
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4256
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4257
sign:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4258
    sign := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4259
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4260
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4261
!LargeInteger methodsFor:'testing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4262
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4263
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4264
    "return true if the receiver is even"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4265
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4266
    ^ (digitByteArray at:1) even
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4267
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4268
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4269
negative
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4270
    "return true, if the receiver is < 0"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4271
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4272
    ^ (sign < 0)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4273
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4274
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4275
odd
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4276
    "return true if the receiver is odd"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4277
1983
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  4278
    ^ (digitByteArray at:1) odd
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  4279
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  4280
    "Modified: 18.11.1996 / 22:19:19 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4281
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4282
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4283
positive
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4284
    "return true, if the receiver is >= 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4285
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4286
    ^ (sign >= 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4287
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4288
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4289
sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4290
    "return the sign of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4291
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4292
    ^ sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4293
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4294
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4295
strictlyPositive
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4296
    "return true, if the receiver is > 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4297
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4298
    ^ (sign > 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4299
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4300
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  4301
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4302
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4303
version
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
  4304
    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.151 1999-11-26 12:43:34 ca Exp $'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4305
! !