LargeInteger.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 03 Sep 2016 09:44:37 +0100
branchjv
changeset 20346 fd33c56536df
parent 19903 bde12a6eb128
parent 20340 56c577d27514
child 20578 39641ba8d6e0
permissions -rw-r--r--
Merge
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
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
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
"
5382
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
    12
"{ Package: 'stx:libbasic' }"
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
    13
17648
8d017b41a3c3 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17246
diff changeset
    14
"{ NameSpace: Smalltalk }"
8d017b41a3c3 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17246
diff changeset
    15
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    16
Integer subclass:#LargeInteger
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
    17
	instanceVariableNames:'sign digitByteArray'
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
    18
	classVariableNames:'UseKarazuba'
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
    19
	poolDictionaries:''
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
    20
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
    23
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    25
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
 COPYRIGHT (c) 1994 by Claus Gittinger
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
    28
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    39
documentation
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    40
"
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
    41
    This class provides arbitrary precision integers.
17128
ec053282f87c class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17035
diff changeset
    42
    These are represented as:
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    43
      sign (-1/0/+1) and, if sign ~~ 0
17128
ec053282f87c class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17035
diff changeset
    44
      the absolute value in a ByteArray of digits with 8 bits per element;
ec053282f87c class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17035
diff changeset
    45
      least significant 8 bits at index 1...
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    46
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    47
    The implementation is not completely tuned for high performance
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    48
    (more key-methods should be rewritten as primitives), although the
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    49
    common operations have been pretty tuned for some architectures.
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    50
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    51
    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
    52
    SmallInteger arithmetic (overflowing the SmallInteger range).
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    53
    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
    54
    SmallIntegers, when possible (see #compressed).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    55
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
    56
    In contrast to ST-80, there is only one class for LargeIntegers,
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
    57
    which keeps the sign as an instance variable
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
    58
    (ST-80 has LargePositiveInteger and LargeNegativeInteger).
17128
ec053282f87c class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17035
diff changeset
    59
    Another possible change is to use 2's complement instead of sign-magnitude
ec053282f87c class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17035
diff changeset
    60
    representation, and to use the underlying CPU's native byte order (instead of LSB).
ec053282f87c class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17035
diff changeset
    61
    This would allow us to use modern CPU vector/longword operations, at least for 64 and
ec053282f87c class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17035
diff changeset
    62
    128 bit numbers (which make up almost all instances in practice).
ec053282f87c class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17035
diff changeset
    63
    As all of these are transparent to the outside world, any of it may or may not
ec053282f87c class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17035
diff changeset
    64
    change in the future.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    65
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    66
    [author:]
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
    67
	Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    68
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    69
    [see also:]
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
    70
	Number
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
    71
	Float Fraction FixedPoint
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
    72
	SmallInteger
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    73
"
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    74
!
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    75
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    76
testing
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    77
"
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    78
   test largeInt multiplication & division
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    79
   (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
    80
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    81
   |last v|
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    82
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    83
   v := last := 1.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    84
   2 to:3000 do:[:i |
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    85
       i printCR.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    86
       v := v * i.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    87
       (v / i) ~= last ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
    88
	   self halt
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    89
       ].
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    90
       last := v.
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    91
   ]
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    92
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    93
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    94
   test addition, subtraction:
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
   SmallInteger maxVal                -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    97
   SmallInteger maxVal + 1            -> 1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    98
   SmallInteger maxVal + 2            -> 1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    99
   (SmallInteger maxVal + 2) - 2      -> 1073741823
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
   SmallInteger minVal                -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   102
   SmallInteger minVal - 1            -> -1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   103
   SmallInteger minVal - 2            -> -1073741826
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   104
   (SmallInteger minVal - 2) + 2      -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   105
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   106
   1234567890 + 10                    -> 1234567900
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   107
   1111111111 + 1111111111            -> 2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   108
   1111111111 - 1111111111            -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   109
   1111111111 - 2222222222            -> -1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   110
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   111
   1111111111 * 2                     -> 2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   112
   1111111111 * -2                    -> -2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   113
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   114
   1111111111 * 1111111111            -> 1234567900987654321
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   115
   1234567900987654321 // 1111111111  -> 1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   116
   1234567900987654321 \\ 1111111111  -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   117
   1234567900987654322 \\ 1111111111  -> 1
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   118
   1234567900987654421 \\ 1111111111  -> 100
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   119
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   120
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   121
   addition:
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   122
   (16rFFFFFFF0 + 1          ) hexPrintString -> 'FFFFFFF1'
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   123
   (16rFFFFFFFF + 1          ) hexPrintString -> '100000000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   124
   (16rFFFFFFFF + 2          ) hexPrintString -> '100000001'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   125
   (16rFFFFFFFF + 16rFFFFFF  ) hexPrintString -> '100FFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   126
   (16rFFFFFFFF + 16rFFFFFFFF) hexPrintString -> '1FFFFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   127
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   128
   20 factorial         -> 2432902008176640000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   129
   20 factorial + 10000 -> 2432902008176650000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   130
   20 factorial               hexPrintString -> '21C3677C82B40000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   131
   (20 factorial + 16rFFFF)   hexPrintString -> '21C3677C82B4FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   132
   (20 factorial + 16rFFFFFF) hexPrintString -> '21C3677C83B3FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   133
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   134
   test comparison:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   135
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   136
   -1234567890 >  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   137
   -1234567890 >= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   138
   -1234567890 <  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   139
   -1234567890 <= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   140
   -1234567890 =  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   141
   -1234567890 ~= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   142
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   143
   -1234567890 >  -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   144
   -1234567890 >= -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   145
   -1234567890 <  -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   146
   -1234567890 <= -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   147
   -1234567890 =  -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   148
   -1234567890 ~= -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   149
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   150
   -1234567891 >  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   151
   -1234567891 >= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   152
   -1234567891 <  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   153
   -1234567891 <= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   154
   -1234567891 =  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   155
   -1234567891 ~= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   156
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         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   159
    1234567890 <  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   160
    1234567890 <= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   161
    1234567890 =  -1234567890         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
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   164
   -1234567890 >  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   165
   -1234567890 >= 1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   166
   -1234567890 <  1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   167
   -1234567890 <= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   168
   -1234567890 =  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   169
   -1234567890 ~= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   170
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   171
    1234567890 >  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   172
    1234567890 >= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   173
    1234567890 <  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   174
    1234567890 <= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   175
    1234567890 =  1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   176
    1234567890 ~= 1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   177
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   178
   -1234567890 >  -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   179
   -1234567890 >= -10                 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
   -1234567890 <= -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   182
   -1234567890 =  -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   183
   -1234567890 ~= -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   184
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   185
   -1234567890 >  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   186
   -1234567890 >= 10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   187
   -1234567890 <  10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   188
   -1234567890 <= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   189
   -1234567890 =  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   190
   -1234567890 ~= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   191
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   192
   -10 >  -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   193
   -10 >= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   194
   -10 <  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   195
   -10 <= -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   196
   -10 =  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   197
   -10 ~= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   198
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   199
    10 >  -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   200
    10 >= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   201
    10 <  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   202
    10 <= -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   203
    10 =  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   204
    10 ~= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   205
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   206
    1234567890 >  -10                 true
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   207
    1234567890 >= -10                 true
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   208
    1234567890 <  -10                 false
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   209
    1234567890 <= -10                 false
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   210
    1234567890 =  -10                 false
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   211
    1234567890 ~= -10                 true
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   212
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   213
    1234567890 >  10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   214
    1234567890 >= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   215
    1234567890 <  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   216
    1234567890 <= 10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   217
    1234567890 =  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   218
    1234567890 ~= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   219
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   220
   -10 >   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   221
   -10 >=  1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   222
   -10 <   1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   223
   -10 <=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   224
   -10 =   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   225
   -10 ~=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   226
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   227
    10 >   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   228
    10 >=  1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   229
    10 <   1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   230
    10 <=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   231
    10 =   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   232
    10 ~=  1234567890                 true
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
   233
"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   234
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   235
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   236
!LargeInteger class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   237
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   238
digitBytes:aByteArrayOfDigits
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   239
    "create and return a new LargeInteger with digits (lsb-first)
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   240
     from the argument, aByteArray.
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
   241
     The byteArray argument provides the unsigned magnitude in lsb-first order."
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   242
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   243
    ^ self basicNew setDigits:aByteArrayOfDigits
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   244
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   245
    "
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   246
     LargeInteger digitBytes:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]
4806
1b48e7420cfe comment
Claus Gittinger <cg@exept.de>
parents: 4794
diff changeset
   247
     (LargeInteger digitBytes:#[16r12 16r34 16r56 16r78 16r90]) hexPrintString
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   248
    "
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   249
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   250
    "Modified: / 8.5.1998 / 21:40:41 / cg"
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   251
!
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   252
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   253
digitBytes:aByteArrayOfDigits MSB:msb
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   254
    "create and return a new LargeInteger with digits (which may be in either msb/lsb order)
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
   255
     from the argument, aByteArray.
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
   256
     The byteArray argument provides the unsigned magnitude in the specified byte order."
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   257
6106
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   258
    |digits|
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   259
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   260
    msb == false ifTrue:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
   261
	digits := aByteArrayOfDigits
6106
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   262
    ] ifFalse:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
   263
	digits := aByteArrayOfDigits reversed
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   264
    ].
6106
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   265
    ^ self basicNew setDigits:digits
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   266
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   267
    "
19606
12f03c97d9bd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19555
diff changeset
   268
     (LargeInteger digitBytes:#[16r10 16r20 16r30 16r40] MSB:false) hexPrintString
12f03c97d9bd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19555
diff changeset
   269
     (LargeInteger digitBytes:#[16r10 16r20 16r30 16r40] MSB:true) hexPrintString
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   270
    "
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   271
!
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   272
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   273
digitBytes:aByteArrayOfDigits sign:sign
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
   274
    "create and return a new sign-magnitude LargeInteger with digits (lsb-first)
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   275
     from the argument, aByteArray.
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
   276
     The byteArray argument provides the unsigned magnitude in lsb-first order."
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   277
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   278
    ^ self basicNew setDigits:aByteArrayOfDigits sign:sign
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   279
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   280
    "
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   281
     LargeInteger digitBytes:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   282
     (LargeInteger digitBytes:#[16r12 16r34 16r56 16r78 16r90]) hexPrintString
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   283
    "
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   284
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   285
    "Modified: / 8.5.1998 / 21:40:41 / cg"
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   286
!
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   287
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   288
new
4299
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   289
    "catch creation message.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   290
     LargeIntegers are only created by system code, which
4299
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   291
     uses basicNew and cares for correct initialization."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   292
a27a279701f8 Initial revision
claus
parents:
diff changeset
   293
    self error:'LargeIntegers cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
   294
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   295
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
new:numberOfDigits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   297
    "catch creation message"
2
claus
parents: 1
diff changeset
   298
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
    self error:'LargeIntegers cannot be created with new'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   300
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   301
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
    "create and return a new LargeInteger with value taken from
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
     the argument, aSmallInteger.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   305
     Notice:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   306
	this should be only used internally, since such small
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   307
	largeIntegers do not normally occur in the system.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   308
	(They are used by myself)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   309
     May change/be removed without notice."
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   310
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   311
    ^ self basicNew value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   312
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
    "LargeInteger value:3689"
3438
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   314
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   315
    "Modified: / 8.5.1998 / 21:40:41 / cg"
701
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
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
   318
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
   319
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   320
!LargeInteger class methodsFor:'queries'!
701
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
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   323
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   324
     Here, true is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   325
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   326
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   327
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   328
    "Modified: 23.4.1996 / 15:59:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   329
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   330
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   331
!LargeInteger methodsFor:'arithmetic'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   332
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   333
* aNumber
11731
f3adbab61060 comment
Claus Gittinger <cg@exept.de>
parents: 11723
diff changeset
   334
    "return the product of the receiver and the argument."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   335
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   336
    |otherSign numberClass|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   337
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   338
    (sign == 0) ifTrue:[^ 0].  "cannot happen if correctly normalized"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   339
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   341
     this is the common case, multiplying with SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   342
     Use a special method for this case ...
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   343
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   344
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   345
	^ self productFromInteger:aNumber
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   346
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   347
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   348
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   349
     if the argument is not a largeInteger, coerce
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   350
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   351
    (numberClass == self class) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   352
	^ self retry:#* coercing:aNumber
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   353
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   354
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   355
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   356
    (sign == otherSign) ifTrue:[^ self absMul:aNumber].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   357
    (otherSign == 0) ifTrue:[^ 0].
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   358
    ^ (self absMul:aNumber) setSign:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   359
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   360
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   361
+ aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   362
    "return the sum of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   363
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   364
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   365
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   366
    (sign == 0) ifTrue:[^ aNumber].  "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   367
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   368
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   369
     this is the common case, adding a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   370
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   371
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   372
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   373
	^ self sumFromInteger:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   374
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   375
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   376
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   377
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   378
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   379
    (numberClass == self class) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   380
	^ self retry:#+ coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   381
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   382
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   383
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   384
    (sign > 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   385
	"I am positive"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   386
	(otherSign > 0) ifTrue:[^ self absPlus:aNumber sign:1].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   387
	(otherSign < 0) ifTrue:[^ self absMinus:aNumber sign:1].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   388
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   389
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   390
    "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
   391
    (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
   392
    (otherSign < 0) ifTrue:[^ self absPlus:aNumber sign:-1].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   393
    ^ self
357
claus
parents: 345
diff changeset
   394
claus
parents: 345
diff changeset
   395
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   396
     SmallInteger maxVal
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   397
     SmallInteger maxVal + 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   398
     SmallInteger maxVal + 2
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   399
     SmallInteger minVal
357
claus
parents: 345
diff changeset
   400
     SmallInteger minVal - 1
claus
parents: 345
diff changeset
   401
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   402
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   403
    "Modified: / 9.1.1998 / 13:26:28 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   404
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   405
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   406
- aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   407
    "return the difference of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   408
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   409
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   410
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   411
    (sign == 0) ifTrue:[^ aNumber negated].     "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   412
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   413
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   414
     this is the common case, subtracting a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   415
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   416
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   417
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   418
	sign > 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   419
	    aNumber > 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   420
		^ self absFastMinus:aNumber sign:1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   421
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   422
	    ^ self absFastPlus:aNumber sign:1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   423
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   424
	aNumber > 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   425
	    ^ self absFastPlus:aNumber sign:-1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   426
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   427
	^ self absFastMinus:aNumber sign:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   428
    ].
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
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   432
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   433
    (numberClass == self class) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   434
	^ self retry:#- coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   435
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   436
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   437
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   438
    (sign > 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   439
	"I am positive"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   440
	(otherSign > 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   441
	    "+large - +large"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   442
	    ^ self absMinus:aNumber sign:1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   443
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   444
	(otherSign < 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   445
	    "+large - -large"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   446
	    ^ self absPlus:aNumber sign:1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   447
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   448
	"should not happen"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   449
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   450
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   451
    "I am negative"
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   452
    (otherSign > 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   453
	"-large - +large"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   454
	^ self absPlus:aNumber sign:-1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   455
    ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   456
    (otherSign < 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   457
	"-large - -large"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   458
	^ self absMinus:aNumber sign:-1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   459
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   460
    ^ self
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   461
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   462
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   463
     12345678901234567890 - 0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   464
     12345678901234567890 - 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   465
     12345678901234567890 - -1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   466
     -12345678901234567890 - 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   467
     -12345678901234567890 - -1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   468
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   469
     12345678901234567890 - 12345678901234567880
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   470
     12345678901234567890 - 12345000000000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   471
     12345678901234567890 - -87654321098765432110
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   472
     -12345678901234567890 - 87654321098765432110
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   473
     -12345678901234567890 - -12345678901234567880
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   474
     -12345678901234567890 - -12345678901234567980
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   475
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   476
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   477
    "Modified: 20.10.1996 / 18:42:16 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   478
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   479
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   480
/ aNumber
1065
77b25fb9f9d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   481
    "return the quotient of the receiver and the argument, aNumber"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   482
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   483
    aNumber isInteger ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   484
	^ Fraction numerator:self denominator:aNumber
14766
ae12897bef55 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 13992
diff changeset
   485
    ].
ae12897bef55 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 13992
diff changeset
   486
    aNumber isFraction ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   487
	^ Fraction numerator:(self * aNumber denominator) denominator:(aNumber numerator)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   488
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   489
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   490
    "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
   491
    ^ (self asFloat / aNumber asFloat)
2793
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   492
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   493
    "Modified: 28.7.1997 / 19:07:55 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   494
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   495
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   496
// aNumber
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
   497
    "return the integer part of the quotient of the receiver's value
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
   498
     and the argument's value.
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   499
     The result is truncated toward negative infinity
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   500
     and will be negative, if the operands signs differ.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   501
     The following is always true:
20340
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   502
        (receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   503
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   504
     Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
20340
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   505
     Especially surprising (because of truncation toward negative infinity):
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   506
        -1 // 10 -> -1 (because -(1/10) is truncated towards next smaller integer, which is -1.
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   507
        -10 // 3 -> -4 (because -(10/3) is truncated towards next smaller integer, which is -4.
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   508
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   509
     See #quo: which truncates toward zero and returns -2 in the above case 
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   510
     and #rem: which is the corresponding remainder."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   511
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   512
    |nrClass divMod quo|
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   513
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   514
    nrClass := aNumber class.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   515
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   516
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   517
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   518
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   519
    "
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   520
    ((nrClass == SmallInteger) or:[ nrClass == self class]) ifFalse:[
20340
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   521
        ^ self retry:#// coercing:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   522
    ].
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   523
    divMod := self absDivMod:aNumber.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   524
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   525
    quo := divMod at:1.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   526
    (sign == aNumber sign) ifFalse:[
20340
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   527
        "/ adjust for truncation if negative and there is a remainder ...
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   528
        "/ be careful: there is one special case to care for here:
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   529
        "/ if quo is maxInt+1, the negation can be represented as a smallInt.
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   530
        quo := quo setSign:-1.
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   531
        (divMod at:2) == 0 ifFalse:[
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   532
            ^ quo - 1
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   533
        ].
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   534
"/        quo digitLength == SmallInteger maxBytes ifTrue:[
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   535
"/            ^ quo compressed
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   536
"/        ].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   537
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   538
    ^ quo
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   539
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   540
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   541
     (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
   542
     (-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
   543
     (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
   544
     (-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
   545
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   546
     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
   547
     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
   548
     16rfffffffff // 16r001fffff  =  32768 ifFalse:[self halt].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   549
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   550
     900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   551
     -900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   552
     900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   553
     -900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   554
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   555
     9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   556
     -9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   557
     9000000000 quo: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   558
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   559
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   560
     0 // 40000000000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   561
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   562
19260
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
   563
    "Modified: / 27-04-1999 / 19:50:26 / stefan"
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
   564
    "Modified: / 26-02-2016 / 22:28:27 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   565
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   566
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   567
\\ aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   568
    "Answer the integer remainder m defined by division with truncation toward
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
   569
     negative infinity.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   570
     m < |aNumber| AND there is an integer k with (k * aNumber + m) = self
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   571
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   572
     The returned remainder has the same sign as aNumber.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   573
     The following is always true:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   574
	(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   575
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   576
     Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
   577
     Especially surprising:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   578
	-1 \\ 10 -> 9  (because -(1/10) is truncated towards next smaller integer, which is -1,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   579
			and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   580
	-10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   581
			and -4 * 4 gives -12, so we need to add 2 to get the original -10.
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   582
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   583
     See #rem: which is the corresponding remainder for division via #quo:.
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   584
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   585
     Redefined here for speed."
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   586
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   587
    |rem negativeDivisor nrClass|
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   588
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   589
    nrClass := aNumber class.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   590
    ((nrClass == SmallInteger) or:[nrClass == self class]) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   591
	^ self retry:#\\ coercing:aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   592
    ].
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   593
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   594
    rem := (self absDivMod:aNumber) at:2.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   595
    rem ~~ 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   596
	negativeDivisor := aNumber negative.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   597
	negativeDivisor ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   598
	    rem := rem setSign:-1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   599
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   600
	(self negative ~~ negativeDivisor) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   601
	    "different sign, so remainder would have been negative.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   602
	     rem has been rounded toward zero, this code will simulate
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   603
	     rounding to negative infinity."
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   604
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   605
	    rem := aNumber - rem.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   606
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   607
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   608
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   609
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   610
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   611
     (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
   612
     (-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
   613
     (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
   614
     (-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
   615
     (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
   616
     (-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
   617
     (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
   618
     (-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
   619
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   620
     9000000000 \\ 7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   621
     -9000000000 \\ 7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   622
     9000000000 \\ -7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   623
     -9000000000 \\ -7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   624
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   625
     900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   626
     -900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   627
     900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   628
     -900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   629
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   630
     9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   631
     -9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   632
     9000000000 rem: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   633
     -9000000000 rem: -4000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   634
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   635
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   636
    "Modified: / 5.11.1996 / 17:10:10 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   637
    "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
   638
!
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   639
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   640
abs
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   641
    "return my absolute value. redefined for speed."
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   642
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   643
    sign >= 0 ifTrue:[^ self].
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   644
    ^ self negated
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   645
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   646
    "Created: / 26.10.1999 / 21:28:06 / stefan"
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   647
!
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   648
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   649
divMod:aNumber
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
   650
    "return an array filled with
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   651
	(self // aNumber) and (self \\ aNumber).
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   652
     The returned remainder has the same sign as aNumber.
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   653
     The following is always true:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   654
	(receiver // something) * something + (receiver \\ something) = receiver
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   655
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   656
     Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
   657
     Especially surprising:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   658
	-1 \\ 10 -> 9  (because -(1/10) is truncated towards next smaller integer, which is -1,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   659
			and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   660
	-10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   661
			and -4 * 4 gives -12, so we need to add 2 to get the original -10.
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
   662
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
   663
     This is redefined here for more performance
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   664
     (as the remainder is generated as a side effect of division)"
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   665
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   666
    |nrClass|
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   667
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   668
    ((self < 0) or:[aNumber <= 0]) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   669
	"/ this is rubbish
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   670
	^ super divMod:aNumber
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   671
    ].
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   672
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   673
    "/ only handle the common case here
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   674
    nrClass := aNumber class.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   675
    (nrClass == SmallInteger) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   676
	(nrClass == self class) ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   677
	    ^ super divMod:aNumber
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   678
	].
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   679
    ].
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   680
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   681
    ^ self absDivMod:aNumber.
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   682
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   683
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   684
     9000000000 // 4000000000   => 2
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   685
     9000000000 \\ 4000000000   => 1000000000
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   686
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   687
     9000000000 divMod: 4000000000   => #(2 1000000000)
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   688
     -9000000000 divMod: 4000000000   => #(-3 3000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   689
     9000000000 divMod: -4000000000   => #(-3 -3000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   690
     -9000000000 divMod: -4000000000   => #(2 -1000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   691
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   692
     9000000000000000000 absDivMod: 400000000000000   => #(22500 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   693
     -9000000000000000000 absDivMod: 400000000000000   => #(22500 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   694
     9000000000000000000 absDivMod: -400000000000000   => #(22500 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   695
     -9000000000000000000 absDivMod: -400000000000000   => #(22500 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   696
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   697
     9000000000000000000 absDivMod: 4000000000000000   => #(2250 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   698
     -9000000000000000000 absDivMod: 4000000000000000   => #(2250 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   699
     9000000000000000000 absDivMod: -4000000000000000   => #(2250 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   700
     -9000000000000000000 absDivMod: -4000000000000000   => #(2250 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   701
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   702
     9000000000000000000 absDivMod: 4000000000000000000   => #(2 1000000000000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   703
     -9000000000000000000 absDivMod: 4000000000000000000   => #(2 1000000000000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   704
     9000000000000000000 absDivMod: -4000000000000000000   => #(2 1000000000000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   705
     -9000000000000000000 absDivMod: -4000000000000000000   => #(2 1000000000000000000)
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   706
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   707
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   708
    "Created: / 29.10.1996 / 21:22:05 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   709
    "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
   710
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   711
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   712
negated
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
   713
    "return an integer with value negated from the receiver's value."
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   714
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   715
    |newNumber sz|
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   716
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   717
    (sign == 0) ifTrue:[^ 0].
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
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   720
     special case for SmallInteger minVal
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   721
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   722
    sign == 1 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   723
	sz := digitByteArray size.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   724
%{
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   725
#ifdef __SCHTEAM__
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   726
#else /* not SCHTEAM */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   727
	int idx;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   728
	unsigned char *bp;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   729
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   730
	bp = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   731
	idx = __intVal(sz);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   732
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   733
	while ((idx > 1) && (bp[idx-1] == 0)) idx--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   734
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   735
	if (idx == sizeof(INT)) {
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   736
# if defined(__LSBFIRST__)
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   737
#  if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   738
	    if ( ((unsigned INT *)bp)[0] == 0x4000000000000000L)
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   739
#  else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   740
	    if ( ((unsigned INT *)bp)[0] == 0x40000000)
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   741
#  endif
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   742
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   743
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   744
	     * generic code
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   745
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   746
	    if ((bp[idx-1] == 0x40)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   747
	     && (bp[idx-2] == 0)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   748
	     && (bp[idx-3] == 0)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   749
	     && (bp[idx-4] == 0)
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   750
#  if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   751
	     && (bp[idx-5] == 0)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   752
	     && (bp[idx-6] == 0)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   753
	     && (bp[idx-7] == 0)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   754
	     && (bp[idx-8] == 0)
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   755
#  endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   756
	    )
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   757
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   758
	    {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   759
		RETURN (__mkSmallInteger(_MIN_INT));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   760
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   761
	}
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   762
#endif
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   763
%}.
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   764
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   765
	sz == SmallInteger maxBytes ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   766
	  (digitByteArray at:1) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   767
	   (digitByteArray at:2) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   768
	    (digitByteArray at:3) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   769
		SmallInteger maxBytes == 8 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   770
		  (digitByteArray at:4) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   771
		   (digitByteArray at:5) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   772
		    (digitByteArray at:6) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   773
		     (digitByteArray at:7) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   774
		      (digitByteArray at:8) == 16r40 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   775
			^ SmallInteger minVal
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   776
		      ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   777
		     ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   778
		    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   779
		   ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   780
		  ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   781
		] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   782
		  (digitByteArray at:4) == 16r40 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   783
		    ^ SmallInteger minVal
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   784
		  ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   785
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   786
	    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   787
	   ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   788
	  ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   789
	].
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   790
    ].
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
   791
    "/ cg - can share the digits ...
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   792
    newNumber := self class digitBytes:digitByteArray sign:(sign negated).
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   793
    ^ newNumber
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   794
!
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   795
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   796
quo:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   797
    "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
   798
     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
   799
     truncates toward negative infinity).
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   800
     The result's sign is negative if the receiver has a sign different from the arg's sign.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   801
     The following is always true:
20340
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   802
        (receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   803
     For positive results, this is the same as #//,
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   804
     for negative results, the remainder is ignored.
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   805
     I.e.: '9 // 4 = 2' and '-9 // 4 = -3'
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   806
     in contrast: '9 quo: 4 = 2' and '-9 quo: 4 = -2'"
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   807
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   808
    |nrClass quo |
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   809
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   810
    nrClass := aNumber class.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   811
    ((nrClass == SmallInteger) or:[ nrClass == self class] ) ifFalse:[
20340
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   812
        ^ self retry:#quo: coercing:aNumber
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   813
    ].
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   814
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   815
    quo := (self absDivMod:aNumber) at:1.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   816
    (sign == aNumber sign) ifTrue:[
20340
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   817
        ^ quo
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   818
    ].
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   819
    ^ quo setSign:-1
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   820
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   821
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   822
     900 // 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   823
     -900 // 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   824
     900 // -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   825
     -900 // -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   826
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   827
     9000000000 // 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   828
     -9000000000 // 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   829
     9000000000 // -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   830
     -9000000000 // -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   831
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   832
     900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   833
     -900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   834
     900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   835
     -900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   836
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   837
     9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   838
     -9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   839
     9000000000 quo: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   840
     -9000000000 quo: -4000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   841
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   842
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   843
    "Modified: / 5.11.1996 / 14:14:17 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   844
    "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
   845
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   846
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   847
rem:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   848
    "return the remainder of division of the receiver by the argument, aNumber.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   849
     The returned remainder has the same sign as the receiver.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   850
     The following is always true:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   851
	(receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   852
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   853
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   854
    |nrClass rem|
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   855
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   856
    nrClass := aNumber class.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   857
    ((nrClass == SmallInteger) or:[ nrClass == self class ]) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   858
	^ self retry:#rem coercing:aNumber
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   859
    ].
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   860
    rem := (self absDivMod:aNumber) at:2.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   861
    rem ~~ 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   862
	sign < 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   863
	    ^ rem setSign:-1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   864
	].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   865
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   866
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   867
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   868
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   869
     900 \\ 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   870
     -900 \\ 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   871
     900 \\ -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   872
     -900 \\ -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   873
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   874
     9000000000 \\ 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   875
     -9000000000 \\ 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   876
     9000000000 \\ -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   877
     -9000000000 \\ -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   878
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   879
     900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   880
     -900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   881
     900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   882
     -900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   883
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   884
     9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   885
     -9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   886
     9000000000 rem: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   887
     -9000000000 rem: -4000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   888
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   889
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   890
    "Modified: / 5.11.1996 / 14:02:59 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   891
    "Modified: / 29.4.1999 / 11:26:51 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   892
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   893
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   894
!LargeInteger methodsFor:'bit operators'!
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   895
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   896
bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   897
    "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
   898
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   899
%{  /* NOCONTEXT */
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   900
    if (__isSmallInteger(anInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   901
	INT v2 = __intVal(anInteger);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   902
	INT v1;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   903
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   904
	v1 = *(INT *)(__byteArrayVal(__INST(digitByteArray)));
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   905
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   906
	unsigned char *digits = (unsigned char *)(__byteArrayVal(__INST(digitByteArray)));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   907
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   908
	v1 = digits[0] & 0xFF;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   909
	v1 = v1 | ((digits[1] & 0xFF)<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   910
	v1 = v1 | ((digits[2] & 0xFF)<<16);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   911
	v1 = v1 | ((digits[3] & 0xFF)<<24);
11605
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   912
# if (__POINTER_SIZE__ == 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   913
	v1 = v1 | ((digits[4] & 0xFF)<<32);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   914
	v1 = v1 | ((digits[5] & 0xFF)<<40);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   915
	v1 = v1 | ((digits[6] & 0xFF)<<48);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   916
	v1 = v1 | ((digits[7] & 0xFF)<<56);
11605
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   917
 #endif
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   918
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   919
	RETURN ( __mkSmallInteger(v1 & v2) );
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   920
    }
11959
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   921
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   922
    if (__isLargeInteger(anInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   923
	OBJ _myDigitByteArray = __INST(digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   924
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(anInteger)->l_digits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   925
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   926
	if (__isByteArray(_myDigitByteArray)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   927
	 && __isByteArray(_otherDigitByteArray)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   928
	    unsigned char *pDigits1, *pDigits2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   929
	    int size1, size2, minSize;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   930
	    union {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   931
		double d;                    // force align
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   932
		unsigned char chars[2048+8];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   933
	    } buffer;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   934
	    unsigned char *pRslt;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   935
	    OBJ newDigits, newLarge;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   936
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   937
	    pDigits1 = (unsigned char *)(__byteArrayVal(_myDigitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   938
	    pDigits2 = (unsigned char *)(__byteArrayVal(_otherDigitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   939
	    pRslt = (void *)(buffer.chars);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   940
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   941
	    size1 = __byteArraySize(_myDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   942
	    size2 = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   943
	    minSize = (size1 < size2) ? size1 : size2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   944
	    if (minSize <= sizeof(buffer.chars)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   945
		int n = minSize;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   946
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   947
	    /* not worth it - but a nice try and first testbed for mmx... */
11959
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   948
#define x__USE_MMX__
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   949
#ifdef __USE_MMX__
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   950
#ifdef __VISUALC__
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   951
		if (((INT)pRslt & 7) == 0) {    // 8-byte aligned
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   952
		    if (((INT)pDigits1 & 7) == ((INT)pDigits2 & 7)) {   // same align
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   953
			while (((INT)pDigits1 & 7) && (n >= sizeof(int))) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   954
			    ((int *)pRslt)[0] = ((int *)pDigits1)[0] & ((int *)pDigits2)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   955
			    pRslt += sizeof(int);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   956
			    pDigits1 += sizeof(int);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   957
			    pDigits2 += sizeof(int);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   958
			    pDigits2 += sizeof(int);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   959
			    n -= sizeof(int);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   960
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   961
			for (; n >= 8; n -= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   962
			    __asm {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   963
				mov eax, pDigits1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   964
				movq mm0, [eax]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   965
				mov eax, pDigits2
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   966
				movq mm1, [eax]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   967
				pand mm0, mm1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   968
				mov eax, pRslt
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   969
				movq [eax], mm0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   970
			    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   971
			    pDigits1 += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   972
			    pDigits2 += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   973
			    pRslt += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   974
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   975
			__asm {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   976
			    emms ; switch back to FPU state.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   977
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   978
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   979
		}
11959
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   980
#endif /* __VISUALC__ */
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   981
#endif /* __USE_MMX__ */
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   982
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   983
		for (; n >= sizeof(INT)*4; n -= sizeof(INT)*4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   984
		    ((INT *)pRslt)[0] = ((INT *)pDigits1)[0] & ((INT *)pDigits2)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   985
		    ((INT *)pRslt)[1] = ((INT *)pDigits1)[1] & ((INT *)pDigits2)[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   986
		    ((INT *)pRslt)[2] = ((INT *)pDigits1)[2] & ((INT *)pDigits2)[2];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   987
		    ((INT *)pRslt)[3] = ((INT *)pDigits1)[3] & ((INT *)pDigits2)[3];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   988
		    pRslt += sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   989
		    pDigits1 += sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   990
		    pDigits2 += sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   991
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   992
		for (; n >= sizeof(INT); n -= sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   993
		    ((INT *)pRslt)[0] = ((INT *)pDigits1)[0] & ((INT *)pDigits2)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   994
		    pRslt += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   995
		    pDigits1 += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   996
		    pDigits2 += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   997
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   998
		for (; n > 0; n--) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   999
		    *pRslt = *pDigits1 & *pDigits2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1000
		    pRslt++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1001
		    pDigits1++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1002
		    pDigits2++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1003
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1004
		// normalize
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1005
		while ((pRslt[-1]==0) && (pRslt > buffer.chars)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1006
		    pRslt--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1007
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1008
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1009
		// allocate result
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1010
		n = pRslt-buffer.chars;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1011
		if (n <= sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1012
		    INT val = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1013
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1014
		    // make it a smallInteger / 32bitInteger
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1015
		    while (n > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1016
			val = (val << 8) + buffer.chars[--n];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1017
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1018
		    RETURN (__MKUINT(val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1019
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1020
		newDigits = __MKBYTEARRAY(buffer.chars, n);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1021
		if (newDigits) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1022
		    __PROTECT__(newDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1023
		    newLarge = __STX___new(sizeof(struct __LargeInteger));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1024
		    __UNPROTECT__(newDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1025
		    if (newLarge) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1026
			__InstPtr(newLarge)->o_class = LargeInteger; __STORE(newLarge, LargeInteger);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1027
			__LargeIntegerInstPtr(newLarge)->l_digits = newDigits; __STORE(newLarge, newDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1028
			__LargeIntegerInstPtr(newLarge)->l_sign = __MKSMALLINT(1);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1029
			RETURN (newLarge);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1030
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1031
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1032
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1033
	}
11959
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
  1034
    }
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1035
%}.
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1036
    ^ super bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1037
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1038
    "
6051
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
  1039
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFF) hexPrintString
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1040
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1041
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1042
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1043
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1044
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1045
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1046
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFFFFFF) hexPrintString
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1047
    "
6051
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
  1048
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
  1049
    "Modified: / 26.9.2001 / 17:34:03 / cg"
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1050
!
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1051
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1052
bitXor:anInteger
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1053
    "return the bitwise-or of the receiver and the argument, anInteger.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1054
     Here, a specially tuned version for largeInteger arguments
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1055
     (to speed up some cryptographic code)"
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1056
15626
d1cacaf45c0c class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15577
diff changeset
  1057
    |len1 len2 newBytes|
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1058
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1059
    anInteger class ~~ LargeInteger ifTrue:[^ super bitXor:anInteger].
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1060
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1061
    (len1 := anInteger digitLength) > (len2 := self digitLength) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1062
	newBytes := anInteger digitBytes copy.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1063
	newBytes bitXorBytesFrom:1 to:len2 with:digitByteArray startingAt:1
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1064
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1065
	newBytes := digitByteArray copy.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1066
	newBytes bitXorBytesFrom:1 to:len1 with:anInteger digits startingAt:1
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1067
    ].
16124
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1068
    ^ (self class digitBytes:newBytes) compressed
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1069
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1070
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1071
     (16r112233445566778899 bitXor:16rFF                ) printStringRadix:16 '112233445566778866'
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1072
     (16r112233445566778899 bitXor:16rFFFFFFFFFFFFFFFF00) printStringRadix:16 'EEDDCCBBAA99887799'
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1073
     (16r112233445566778899 bitXor:16rFF0000000000000000) printStringRadix:16 'EE2233445566778899'
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1074
     (16r112233445566778899 bitXor:16r112233445566778800) printStringRadix:16 '99'
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1075
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1076
     |bigNum1 bigNum2|
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1077
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1078
     bigNum1 := 2 raisedToInteger:512.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1079
     bigNum2 := 2 raisedToInteger:510.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1080
     Time millisecondsToRun:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1081
	1000000 timesRepeat:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1082
	   bigNum1 bitXor:bigNum2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1083
	]
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1084
     ]
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1085
    "
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1086
!
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1087
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1088
lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1089
    "return the bitIndex of the lowest bit set. The returned bitIndex
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1090
     starts at 1 for the least significant bit.
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1091
     Returns 0 if no bit is set.
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1092
     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
  1093
     Redefined here for more performance of the gcd: algorithm, which
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1094
     is used when big fractions are reduced (should we write a primitive for this ?)."
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1095
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1096
    |sz   "{ Class: SmallInteger }"
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1097
     idx0 "{ Class: SmallInteger }"
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1098
     byte|
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1099
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1100
    idx0 := 1.
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1101
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1102
%{
12746
10866527a1ab changed: #lowBit
Claus Gittinger <cg@exept.de>
parents: 12121
diff changeset
  1103
    OBJ __digitByteArray = __INST(digitByteArray);
10866527a1ab changed: #lowBit
Claus Gittinger <cg@exept.de>
parents: 12121
diff changeset
  1104
7544
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1105
    /*
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1106
     * quickly advance over full 0-words
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1107
     */
12746
10866527a1ab changed: #lowBit
Claus Gittinger <cg@exept.de>
parents: 12121
diff changeset
  1108
    if (__isByteArray(__digitByteArray)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1109
	int __sz = __byteArraySize(__digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1110
	unsigned char *__bP = __byteArrayVal(__digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1111
	unsigned char *__bP0 = __bP;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1112
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1113
	sz = __MKSMALLINT(__sz);
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1114
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1115
#ifdef __UNROLL_LOOPS__
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1116
	while (__sz > (sizeof(INT) * 4)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1117
	    if (( ((INT *)__bP)[0]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1118
		 | ((INT *)__bP)[1]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1119
		 | ((INT *)__bP)[2]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1120
		 | ((INT *)__bP)[3] ) != 0) break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1121
	    __sz -= sizeof(INT) * 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1122
	    __bP += sizeof(INT) * 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1123
	}
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1124
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1125
	while (__sz > sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1126
	    if ( ((INT *)__bP)[0] != 0 ) break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1127
	    __sz -= sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1128
	    __bP += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1129
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1130
	while (__sz > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1131
	    unsigned int c;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1132
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1133
	    if ( (c = *__bP) != 0 ) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1134
		int bitIdx = (__bP - __bP0) * 8;
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1135
#ifdef __BSF
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1136
		{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1137
		    int index;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1138
		    int t = c;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1139
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1140
		    index = __BSF(t);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1141
		    RETURN ( __mkSmallInteger(index + 1 + bitIdx) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1142
		}
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1143
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1144
		if (c & 0x0F) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1145
		    if (c & 0x03) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1146
			if (c & 0x01) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1147
			    RETURN ( __mkSmallInteger( bitIdx + 1) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1148
			} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1149
			    RETURN ( __mkSmallInteger( bitIdx + 2) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1150
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1151
		    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1152
			if (c & 0x04) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1153
			    RETURN ( __mkSmallInteger( bitIdx + 3) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1154
			} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1155
			    RETURN ( __mkSmallInteger( bitIdx + 4) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1156
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1157
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1158
		} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1159
		    if (c & 0x30) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1160
			if (c & 0x10) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1161
			    RETURN ( __mkSmallInteger( bitIdx + 5) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1162
			} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1163
			    RETURN ( __mkSmallInteger( bitIdx + 6) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1164
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1165
		    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1166
			if (c & 0x40) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1167
			    RETURN ( __mkSmallInteger( bitIdx + 7) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1168
			} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1169
			    RETURN ( __mkSmallInteger( bitIdx + 8) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1170
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1171
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1172
		}
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1173
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1174
		break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1175
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1176
	    __sz--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1177
	    __bP++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1178
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1179
	idx0 = __mkSmallInteger( __bP - __bP0 + 1 );
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1180
    }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1181
%}.
12746
10866527a1ab changed: #lowBit
Claus Gittinger <cg@exept.de>
parents: 12121
diff changeset
  1182
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1183
    "/ never actually reached
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1184
    idx0 to:sz do:[:digitIndex |
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1185
	(byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1186
	    ^ (digitIndex-1)*8 + (byte lowBit)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1187
	]
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1188
    ].
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1189
    ^ 0 "/ should not happen
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1190
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1191
    "
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  1192
     (1 bitShift:0) lowBit
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1193
     (1 bitShift:10) lowBit
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1194
     (1 bitShift:20) lowBit
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1195
     (1 bitShift:30) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1196
     (1 bitShift:30) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1197
     (1 bitShift:31) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1198
     (1 bitShift:31) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1199
     (1 bitShift:32) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1200
     (1 bitShift:32) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1201
     (1 bitShift:33) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1202
     (1 bitShift:33) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1203
     (1 bitShift:64) lowBit
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  1204
     (1 bitShift:64) highBit
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1205
     (1 bitShift:1000) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1206
     (1 bitShift:1000) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1207
     ((1 bitShift:64)-1) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1208
     ((1 bitShift:64)-1) highBit
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1209
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1210
     1 to:1000 do:[:idx |
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1211
	self assert:(( 1 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1212
	self assert:(( 1 bitShift:idx) lowBit = ( 1 bitShift:idx) highBit).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1213
	self assert:(( 3 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1214
	self assert:(( 7 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1215
	self assert:(( 15 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1216
	self assert:(( 31 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1217
	self assert:(( 63 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1218
	self assert:(( 127 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1219
	self assert:(( 255 bitShift:idx) lowBit = (idx+1)).
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1220
     ]
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1221
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1222
     |num|
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1223
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1224
     num := (1 bitShift:1000).
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1225
     Time millisecondsToRun:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1226
	1000000 timesRepeat:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1227
	    num lowBit
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1228
	]
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1229
     ]
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1230
    "
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1231
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1232
    "Modified: 14.8.1997 / 11:55:34 / cg"
19052
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1233
! !
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1234
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1235
!LargeInteger methodsFor:'bit operators - indexed'!
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1236
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1237
bitAt:anIntegerIndex
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1238
    "return the value of the index's bit (index starts at 1) as 0 or 1.
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1239
     Notice: the result of bitAt: on negative receivers is not
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1240
	     defined in the language standard (since the implementation
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1241
	     is free to choose any internal representation for integers)"
19052
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1242
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1243
%{  /* NOCONTEXT */
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1244
    if (__isSmallInteger(anIntegerIndex)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1245
	INT idx = __smallIntegerVal(anIntegerIndex) - 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1246
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1247
	if (idx >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1248
	    int v1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1249
	    int byteOffset = idx / 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1250
	    int digitLen   = __byteArraySize(__INST(digitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1251
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1252
	    if (digitLen < byteOffset) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1253
		RETURN(__mkSmallInteger(0));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1254
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1255
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1256
	    v1 = (__byteArrayVal(__INST(digitByteArray)))[byteOffset];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1257
	    if (v1 & (1 << (idx % 8))) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1258
		RETURN(__mkSmallInteger(1));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1259
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1260
		RETURN(__mkSmallInteger(0));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1261
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1262
	}
19052
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1263
    }
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1264
%}.
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1265
    ^ super bitAt:anIntegerIndex
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1266
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1267
    "
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1268
     TestCase should:[ 16rFFFFFFFFFF01 bitAt:0 ] raise:Error
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1269
     TestCase assert:( 16rFFFFFFFFFF01 bitAt:49 ) == 0
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1270
     TestCase assert:( 16rFFFFFFFFFF01 bitAt:1  ) == 1
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1271
     TestCase assert:( 16rFFFFFFFFFF01 bitAt:2  ) == 0
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1272
     TestCase assert:( 16rFFFFFFFFFF02 bitAt:2  ) == 1
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1273
     TestCase assert:( 16rFFFFFFFF01FF bitAt:8  ) == 1
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1274
     TestCase assert:( 16rFFFFFFFF01FF bitAt:9  ) == 1
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1275
     TestCase assert:( 16rFFFFFFFF01FF bitAt:10 ) == 0
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1276
    "
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1277
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1278
    "Modified: / 10-08-2010 / 12:33:04 / cg"
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1279
!
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1280
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1281
setBit:index
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1282
    "return a new integer, where the specified bit is on.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1283
     Bits are counted from 1 starting with the least significant.
15132
83d908af0aa1 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 14766
diff changeset
  1284
     The methods name may be misleading: the receiver is not changed,
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1285
     but a new number is returned. Should be named #withBitSet:"
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1286
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1287
    |myDigitLength newDigitLength newDigitBytes byteIndexOfBitToSet|
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1288
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1289
    index <= 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1290
	^ SubscriptOutOfBoundsSignal
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1291
		raiseRequestWith:index
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1292
		errorString:'index out of bounds'
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1293
    ].
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1294
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1295
    myDigitLength := digitByteArray size.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1296
    byteIndexOfBitToSet := ((index-1)//8)+1.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1297
    byteIndexOfBitToSet > myDigitLength ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1298
	newDigitLength := myDigitLength max:byteIndexOfBitToSet.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1299
	newDigitBytes := ByteArray new:newDigitLength.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1300
	newDigitBytes replaceFrom:1 to:myDigitLength with:digitByteArray startingAt:1.
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1301
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1302
	newDigitBytes := digitByteArray copy
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1303
    ].
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  1304
    newDigitBytes
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1305
	at:byteIndexOfBitToSet
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1306
	put:((newDigitBytes at:byteIndexOfBitToSet) setBit:(((index-1)\\8)+1)).
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  1307
    ^ self class digitBytes:newDigitBytes sign:sign
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1308
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1309
    "
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  1310
     TestCase assert:( 16r80000000 setBit:3  ) = 16r80000004
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  1311
     TestCase assert:( 16r80000000 setBit:33 ) = 16r180000000
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1312
    "
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1313
! !
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1314
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1315
!LargeInteger methodsFor:'bit operators-32bit'!
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1316
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1317
bitInvert32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1318
    "return the value of the receiver with all bits inverted in 32bit signed int space
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1319
     (changes the sign)"
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1320
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1321
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1322
    unsigned INT v;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1323
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1324
    v = __unsignedLongIntVal(self);
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1325
    v = ~v;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1326
#if __POINTER_SIZE__ == 8
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1327
    v &= 0xFFFFFFFFL;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1328
#endif
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1329
    RETURN ( __MKUINT(v) );
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1330
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1331
    ^ self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1332
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1333
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1334
     16r80000000 bitInvert32 hexPrintString
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1335
     16r7FFFFFFF bitInvert32 hexPrintString
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1336
     16rFFFFFFFF bitInvert32 hexPrintString
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1337
     0 bitInvert32 hexPrintString
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1338
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1339
!
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1340
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1341
bitRotate32:shiftCount
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1342
    "return the value of the receiver rotated by shiftCount bits,
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1343
     but only within 32 bits, rotating left for positive, right for negative counts.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1344
     Rotates through the sign bit.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1345
     Useful for crypt algorithms, or to emulate C/Java semantics."
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1346
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1347
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1348
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1349
    unsigned INT bits;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1350
    int count;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1351
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1352
    if (__isSmallInteger(shiftCount)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1353
	count = __intVal(shiftCount);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1354
	count = count % 32;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1355
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1356
	bits = __unsignedLongIntVal(self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1357
	if (count > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1358
	    bits = (bits << count) | (bits >> (32-count));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1359
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1360
	    bits = (bits >> (-count)) | (bits << (32-(-count)));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1361
	}
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1362
#if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1363
	bits &= 0xFFFFFFFFL;
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1364
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1365
	RETURN (__MKUINT(bits));
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1366
    }
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1367
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1368
    ^ self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1369
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1370
    "
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1371
     (1 bitShift32:31) rotate32:0
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1372
     (1 bitShift32:31) rotate32:1
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1373
     (1 bitShift32:31) rotate32:-1
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1374
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1375
!
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1376
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1377
bitShift32:shiftCount
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1378
    "return the value of the receiver shifted by shiftCount bits,
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1379
     but only within 32 bits, shifting into/out-of the sign bit.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1380
     May be useful for communication interfaces, to create ST-numbers
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1381
     from a signed 32bit int value given as individual bytes,
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1382
     or to emulate C/Java semantics.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1383
     The shift is unsigned"
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1384
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1385
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1386
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1387
    unsigned INT bits;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1388
    int count;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1389
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1390
    if (__isSmallInteger(shiftCount)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1391
	count = __intVal(shiftCount);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1392
	if (count >= 32) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1393
	    RETURN (__mkSmallInteger(0));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1394
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1395
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1396
	bits = __unsignedLongIntVal(self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1397
	if (count > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1398
	    bits = bits << count;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1399
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1400
	    bits = bits >> (-count);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1401
	}
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1402
#if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1403
	bits &= 0xFFFFFFFFL;
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1404
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1405
	RETURN (__MKUINT(bits));
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1406
    }
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1407
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1408
    ^ self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1409
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1410
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1411
     128 bitShift:24
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1412
     128 bitShift32:24
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1413
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1414
     1 bitShift:31
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1415
     1 bitShift32:31
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1416
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1417
!
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1418
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1419
bitXor32:aNumber
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1420
    "return the xor of the receiver and the argument.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1421
     The argument must be a SmallInteger or a 4-byte LargeInteger.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1422
     If the result overflows the 32 bit range, the value modulo 16rFFFFFFFF is returned.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1423
     This is of course not always correct, but allows for C/Java behavior to be emulated."
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1424
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1425
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1426
    INT rslt;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1427
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1428
    rslt =  __unsignedLongIntVal(self) ^ __unsignedLongIntVal(aNumber);
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1429
#if __POINTER_SIZE__ == 8
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1430
    rslt &= 0xFFFFFFFFL;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1431
#endif
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1432
    RETURN ( __MKUINT(rslt));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1433
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1434
    self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1435
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1436
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1437
     16r7FFFFFFF bitXor: 16r80000000          4294967295
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1438
     16r7FFFFFFF bitXor32: 16r80000000
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1439
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1440
! !
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1441
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1442
!LargeInteger methodsFor:'byte access'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1443
13992
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1444
byteSwapped
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1445
    "lsb -> msb;
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1446
     i.e. a.b ... y.z -> z.y. ... b.a"
13992
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1447
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1448
    ^ self class digitBytes:digitByteArray MSB:true
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1449
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1450
    "
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1451
     (LargeInteger value:16r11223344) byteSwapped hexPrintString
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1452
     (LargeInteger value:16r44332211) byteSwapped hexPrintString
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1453
     16r88776655 byteSwapped hexPrintString
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1454
     16r11223344 byteSwapped hexPrintString
13992
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1455
    "
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1456
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1457
    "Created: / 31-01-2012 / 11:07:42 / cg"
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1458
!
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1459
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1460
byteSwapped32
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1461
    "byte swap a 32bit value; lsb -> msb;
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1462
     i.e. a.b.c.d -> d.c.b.a
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1463
     Useful for communication protocols"
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1464
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1465
%{
15909
9ffe9886b91b class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15908
diff changeset
  1466
    unsigned INT swapped;
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1467
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1468
    swapped = ( (__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[0]) << 24)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1469
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[1]) << 16)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1470
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[2]) << 8)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1471
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[3]));
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1472
    RETURN (__MKUINT(swapped));
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1473
%}.
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1474
    ^ super byteSwapped32
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1475
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1476
    "
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1477
     (LargeInteger value:16r11223344) byteSwapped32 hexPrintString
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1478
     (LargeInteger value:16r44332211) byteSwapped32 hexPrintString
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1479
     16r88776655 byteSwapped32 hexPrintString
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1480
     16r11223344 byteSwapped32 hexPrintString
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1481
    "
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1482
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1483
    "Created: / 31-01-2012 / 11:07:42 / cg"
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1484
!
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1485
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1486
byteSwapped64
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1487
    "byte swap a 64bit value; lsb -> msb;
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1488
     i.e. a.b.c.d.e.f.g.h -> h.g.f.e.d.c.b.a
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1489
     Useful for communication protocols"
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1490
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1491
%{
15909
9ffe9886b91b class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15908
diff changeset
  1492
    unsigned INT swappedLO = 0;
9ffe9886b91b class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15908
diff changeset
  1493
    unsigned INT swappedHI;
9ffe9886b91b class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15908
diff changeset
  1494
    unsigned INT swapped;
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1495
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1496
    swappedHI = ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[0]) << 24)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1497
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[1]) << 16)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1498
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[2]) << 8)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1499
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[3]));
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1500
    if (__byteArraySize(__INST(digitByteArray)) > 4) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1501
	swappedLO = ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[4]) << 24)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1502
		  | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[5]) << 16)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1503
		  | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[6]) << 8)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1504
		  | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[7]));
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1505
    }
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1506
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1507
#if __POINTER_SIZE__ == 8
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1508
    swapped = (swappedHI<<32) | swappedLO;
16520
a1a1d558cfa3 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 16124
diff changeset
  1509
    RETURN(__MKUINT( swapped ));
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1510
#else
16520
a1a1d558cfa3 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 16124
diff changeset
  1511
    RETURN(__MKLARGEINT64(1, swappedLO, swappedHI));
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1512
#endif
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1513
%}.
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1514
    ^ super byteSwapped64
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1515
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1516
    "
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1517
     (LargeInteger value:16r11223344) byteSwapped64 hexPrintString
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1518
     (LargeInteger value:16r44332211) byteSwapped64 hexPrintString
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1519
     (LargeInteger value:16r1122334455667788) byteSwapped64 hexPrintString
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1520
     (LargeInteger value:16r8877665544332211) byteSwapped64 hexPrintString
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1521
     16r88776655 byteSwapped hexPrintString
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1522
     16r11223344 byteSwapped hexPrintString
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1523
    "
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1524
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1525
    "Created: / 31-01-2012 / 11:07:42 / cg"
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1526
!
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1527
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1528
digitAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1529
    "return 8 bits of value, starting at byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1530
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1531
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  1532
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1533
    return context._RETURN( ((STLargeInteger)self).digitAt( index.intValue() ) );
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1534
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1535
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1536
    index > digitByteArray size ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1537
    ^ digitByteArray at:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1538
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1539
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1540
digitAt:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1541
    "set the 8 bits, index is a byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1542
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1543
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  1544
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1545
    ERROR("cannot modify the digits of a LargeInteger");
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1546
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1547
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1548
    digitByteArray at:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1549
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1550
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1551
digitByteAt:index
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1552
    "return 8 bits of my signed value, starting at byte index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1553
     For positive receivers, this is the same as #digitAt:;
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1554
     for negative ones, the actual bit representation is returned."
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1555
18900
ace3f7e03da3 #DOCUMENTATION
Stefan Vogel <sv@exept.de>
parents: 18899
diff changeset
  1556
    |digits|
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1557
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1558
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  1559
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1560
    return context._RETURN( ((STLargeInteger)self).digitByteAt( index.intValue() ) );
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1561
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1562
%}.
6359
fcb206734265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6106
diff changeset
  1563
    sign >= 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1564
	index > digitByteArray size ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1565
	    ^ 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1566
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1567
	^ digitByteArray at:index.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1568
    ].
6359
fcb206734265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6106
diff changeset
  1569
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1570
    "/ negative int - do 2's complement here
18900
ace3f7e03da3 #DOCUMENTATION
Stefan Vogel <sv@exept.de>
parents: 18899
diff changeset
  1571
    digits := (self bitInvert + 1) digitBytes.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1572
    index > digits size ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1573
	^ 16rFF
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1574
    ].
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1575
    ^ digits at:index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1576
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1577
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1578
     16r11111111111111111111 negated digitByteAt:1
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1579
     0 asLargeInteger digitByteAt:1
18900
ace3f7e03da3 #DOCUMENTATION
Stefan Vogel <sv@exept.de>
parents: 18899
diff changeset
  1580
     -1 asLargeInteger digitByteAt:1
ace3f7e03da3 #DOCUMENTATION
Stefan Vogel <sv@exept.de>
parents: 18899
diff changeset
  1581
     -1 digitByteAt:1
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1582
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1583
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1584
    "Created: / 25.10.1998 / 14:12:21 / cg"
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1585
!
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1586
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1587
digitBytes
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  1588
    "return a byteArray filled with the receiver's bits
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1589
     (8 bits of the absolute value per element).
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1590
     Least significant byte is first!!"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1591
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1592
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  1593
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1594
    return context._RETURN( ((STLargeInteger)self).digitBytes() );
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1595
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1596
%}.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1597
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1598
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1599
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1600
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1601
15569
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1602
digitBytesMSB
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  1603
    "return a byteArray filled with the receiver's bits
15569
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1604
     (8 bits of the absolute value per element),
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1605
     most significant byte first"
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1606
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1607
     ^ digitByteArray copyReverse.
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1608
!
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1609
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1610
digitBytesMSB:msbFlag
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  1611
    "return a byteArray filled with the receiver's bits
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1612
     (8 bits of the absolute value per element),
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1613
     if msbflag = true, most significant byte is first,
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1614
     otherwise least significant byte is first"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1615
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1616
    msbFlag ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1617
	^ digitByteArray copyReverse.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1618
    ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1619
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1620
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1621
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1622
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1623
18899
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1624
digitBytesSigned
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1625
    "return a byteArray filled with the receiver's bits
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1626
     (8 bits of the value (which may be negative) per element).
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1627
     Least significant byte is first!!"
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1628
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1629
    sign > 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1630
	^ digitByteArray
18899
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1631
    ].
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1632
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1633
    "answer the 2's complement"
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1634
    ^ (self bitInvert + 1) digitBytes.
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1635
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1636
    "
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1637
	16r12345678901234567890 digitBytesSigned
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1638
	-16r12345678901234567890 digitBytesSigned
18899
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1639
    "
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1640
!
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1641
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1642
digitLength
19320
bf817fb15805 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19262
diff changeset
  1643
    "return the number of bytes needed for the unsigned binary representation of the receiver.
bf817fb15805 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19262
diff changeset
  1644
     For negative receivers, the result is not defined by the language standard.
bf817fb15805 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19262
diff changeset
  1645
     ST/X returns the digitLength of its absolute value."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1646
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1647
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1648
     check if there is a 0-byte ...
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1649
     this allows to ask unnormalized LargeIntegers
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1650
     for their digitLength
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1651
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1652
    |l "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1653
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1654
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  1655
#ifdef __SCHTEAM__
18709
Claus Gittinger <cg@exept.de>
parents: 18621
diff changeset
  1656
    return context._RETURN( STInteger._new( ((STLargeInteger)self).digitLength() ));
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1657
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1658
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1659
    l := digitByteArray size.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1660
    [l ~~ 0 and:[(digitByteArray at:l) == 0]] whileTrue:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  1661
	l := l - 1.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1662
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1663
    ^ l
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1664
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1665
    "Modified: 31.7.1997 / 13:18:28 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1666
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1667
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1668
digits
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1669
    "obsolete, use #digitBytes"
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1670
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1671
    <resource:#obsolete>
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1672
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1673
    ^ digitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1674
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1675
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1676
!LargeInteger methodsFor:'coercing & converting'!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1677
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1678
asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1679
    "return a LargeInteger with same value as myself - thats me"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1680
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1681
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1682
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1683
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1684
asSigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1685
    "return a 32-bit integer with my bit-pattern. Receiver must be unsigned (i.e. positive).
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1686
     May be required for bit operations on the sign-bit and/or to
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1687
     convert C/Java numbers."
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1688
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1689
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1690
    int rslt;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1691
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1692
    rslt =  (int)(__unsignedLongIntVal(self));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1693
    RETURN ( __MKINT(rslt));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1694
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1695
    self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1696
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1697
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1698
     16r80000000 asSigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1699
     16r40000000 asSigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1700
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1701
!
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1702
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1703
asSmallInteger
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1704
    "return a SmallInteger with same value as myself -
18845
ee0ed4f54c44 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18709
diff changeset
  1705
     the result is invalid if the receiver's value cannot
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1706
     be represented as a SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1707
     Q: should we raise an exception if this happens ?"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1708
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1709
    |value|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1710
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1711
    value := 0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1712
    (sign == 0) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1713
	digitByteArray reverseDo:[:aDigit |
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1714
	    value := (value times:256) + aDigit
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1715
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1716
	(sign < 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1717
	    value := value negated
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1718
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1719
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1720
    ^ value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1721
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1722
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1723
asUnsigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1724
    "return a 32-bit integer with my bit-pattern. Receiver must be unsigned (i.e. positive).
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1725
     May be required for bit operations on the sign-bit and/or to
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1726
     convert C/Java numbers."
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1727
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1728
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1729
    unsigned int rslt;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1730
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1731
    rslt =  (int)(__unsignedLongIntVal(self));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1732
    RETURN ( __MKUINT(rslt));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1733
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1734
    self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1735
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1736
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1737
     16r80000000 asUnsigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1738
     16r40000000 asUnsigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1739
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1740
!
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1741
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1742
coerce:aNumber
18845
ee0ed4f54c44 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18709
diff changeset
  1743
    "convert the argument aNumber into an instance of the receiver's class and return it."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1744
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1745
    ^ aNumber asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1746
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1747
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1748
compressed
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1749
    "if the receiver can be represented as a SmallInteger, return
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1750
     a SmallInteger with my value;
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1751
     otherwise remove leading zero bytes in the digitByte array
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1752
     and return the receiver"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1753
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1754
    |index "{ Class: SmallInteger }"
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1755
     val   "{ Class: SmallInteger }"
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1756
     index0
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1757
    |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1758
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1759
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1760
    OBJ t;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1761
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1762
    if (__INST(sign) == __mkSmallInteger(0)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1763
	RETURN (__mkSmallInteger(0));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1764
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1765
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1766
    t = __INST(digitByteArray);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1767
    if (__isByteArray(t)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1768
	unsigned char *__digitBytes = __ByteArrayInstPtr(t)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1769
	int _idx, _idx0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1770
	INT _val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1771
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1772
	_idx = _idx0 = __byteArraySize(t);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1773
	while ((_idx > 0) && (__digitBytes[_idx - 1] == 0)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1774
	    _idx--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1775
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  1776
#if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1777
	switch (_idx) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1778
	    case 8:
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1779
		_val = __digitBytes[7];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1780
		if (_val <= 0x40) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1781
		    _val = (_val<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1782
		    _val = (_val + __digitBytes[6]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1783
		    _val = (_val + __digitBytes[5]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1784
		    _val = (_val + __digitBytes[4]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1785
		    _val = (_val + __digitBytes[3]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1786
		    _val = (_val + __digitBytes[2]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1787
		    _val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1788
		    _val += __digitBytes[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1789
		    if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1790
			_val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1791
		    if (__ISVALIDINTEGER(_val)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1792
			RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1793
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1794
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1795
		break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1796
	    case 7:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1797
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1798
		_val = ((INT *)__digitBytes)[0] & 0x00FFFFFFFFFFFFFFL;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1799
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1800
		_val = (__digitBytes[6]<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1801
		_val = (_val + __digitBytes[5]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1802
		_val = (_val + __digitBytes[4]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1803
		_val = (_val + __digitBytes[3]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1804
		_val = (_val + __digitBytes[2]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1805
		_val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1806
		_val += __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1807
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1808
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1809
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1810
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1811
	    case 6:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1812
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1813
		_val = ((INT *)__digitBytes)[0] & 0x0000FFFFFFFFFFFFL;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1814
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1815
		_val = (__digitBytes[5]<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1816
		_val = (_val + __digitBytes[4]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1817
		_val = (_val + __digitBytes[3]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1818
		_val = (_val + __digitBytes[2]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1819
		_val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1820
		_val += __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1821
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1822
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1823
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1824
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1825
	    case 5:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1826
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1827
		_val = ((INT *)__digitBytes)[0] & 0x000000FFFFFFFFFFL;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1828
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1829
		_val = (__digitBytes[4]<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1830
		_val = (_val + __digitBytes[3]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1831
		_val = (_val + __digitBytes[2]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1832
		_val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1833
		_val += __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1834
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1835
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1836
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1837
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1838
	    case 4:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1839
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1840
		_val = ((INT *)__digitBytes)[0] & 0x00000000FFFFFFFFL;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1841
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1842
		_val = (__digitBytes[3]<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1843
		_val = (_val + __digitBytes[2]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1844
		_val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1845
		_val += __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1846
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1847
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1848
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1849
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1850
	    case 3:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1851
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1852
		_val = ((int *)__digitBytes)[0] & 0x00FFFFFF;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1853
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1854
		_val = (__digitBytes[2]<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1855
		_val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1856
		_val += __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1857
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1858
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1859
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1860
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1861
	    case 2:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1862
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1863
		_val = ((int *)__digitBytes)[0] & 0x0000FFFF;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1864
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1865
		_val = (__digitBytes[1]<<8) + __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1866
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1867
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1868
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1869
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1870
	    case 1:
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1871
		_val = __digitBytes[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1872
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1873
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1874
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1875
	    case 0:
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1876
		RETURN (__mkSmallInteger(0));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1877
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1878
	}
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1879
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1880
	if (_idx <= 4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1881
	    if (_idx <= 2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1882
		if (_idx == 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1883
		    RETURN (__mkSmallInteger(0));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1884
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1885
		if (_idx == 1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1886
		    _val = __digitBytes[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1887
		    if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1888
			_val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1889
		    RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1890
		}
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1891
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1892
		_val = ((int *)__digitBytes)[0] & 0x0000FFFF;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1893
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1894
		_val = (__digitBytes[1]<<8) + __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1895
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1896
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1897
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1898
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1899
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1900
	    if (_idx == 3) {
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1901
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1902
		_val = ((int *)__digitBytes)[0] & 0x00FFFFFF;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1903
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1904
		_val = (((__digitBytes[2]<<8) + __digitBytes[1])<<8) + __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1905
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1906
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1907
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1908
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1909
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1910
	    _val = __digitBytes[3];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1911
	    if (_val <= 0x40) {
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1912
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1913
		_val = ((int *)__digitBytes)[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1914
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1915
		_val = (((((_val<<8) + __digitBytes[2])<<8) + __digitBytes[1])<<8) + __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1916
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1917
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1918
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1919
		if (__ISVALIDINTEGER(_val)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1920
		    RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1921
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1922
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1923
	}
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1924
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1925
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1926
	if (_idx == _idx0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1927
	    RETURN (self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1928
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1929
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1930
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1931
	 * must copy & cut off some (zero)bytes
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1932
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1933
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1934
	    OBJ newDigits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1935
	    OBJ oldDigits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1936
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1937
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1938
	     * careful - there is no context here to protect
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1939
	     * the receiver ...
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1940
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1941
	    __PROTECT__(self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1942
	    __PROTECT__(__INST(digitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1943
	    newDigits = __BYTEARRAY_UNINITIALIZED_NEW_INT(_idx);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1944
	    __UNPROTECT__(oldDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1945
	    __UNPROTECT__(self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1946
	    if (newDigits) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1947
		bcopy(__ByteArrayInstPtr(oldDigits)->ba_element,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1948
		      __ByteArrayInstPtr(newDigits)->ba_element,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1949
		      _idx);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1950
		__INST(digitByteArray) = newDigits; __STORE(self, newDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1951
		RETURN (self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1952
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1953
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1954
	     * allocation failed ...
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1955
	     * ... fall through to trigger the error
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1956
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1957
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1958
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1959
%}.
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1960
    index0 := index := digitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1961
    [(index > 0) and:[(digitByteArray at:index) == 0]] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1962
	index := index - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1963
    ].
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1964
"/    ((index < SmallInteger maxBytes)
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1965
"/    or:[(index == SmallInteger maxBytes)
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1966
"/            and:[(digitByteArray at:index) < 16r20]])
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1967
"/    ifTrue:[
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1968
"/        val := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1969
"/        1 to:index do:[:i |
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1970
"/            val := val bitShift:8.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1971
"/            val := val bitOr:(digitByteArray at:i).
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1972
"/        ].
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1973
"/        ^ val * sign
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1974
"/    ].
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1975
    (index ~~ index0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1976
	digitByteArray := digitByteArray copyFrom:1 to:index
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1977
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1978
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1979
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1980
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1981
generality
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1982
    "return the generality value - see ArithmeticValue>>retry:coercing:"
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1983
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1984
    ^ 40
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1985
!
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1986
16124
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1987
nilAllInstvars
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1988
    digitByteArray nilAllInstvars.
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1989
    digitByteArray := sign := nil.
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1990
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1991
    "
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1992
      100 factorial nilAllInstvars
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1993
    "
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1994
!
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1995
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1996
value:aSmallInteger
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1997
    "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
  1998
     This method will fail, if the argument is not a smallInteger.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1999
     This should only be used internally,
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  2000
     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
  2001
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2002
    |absValue
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2003
     b1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2004
     b2 "{ Class: SmallInteger }"
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2005
     b3 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2006
     b4 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2007
     b5 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2008
     b6 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2009
     b7 "{ Class: SmallInteger }"|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2010
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2011
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2012
     could have simply created a 4-byte largeinteger and normalize it.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  2013
     The code below does the normalize right away, avoiding the
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2014
     overhead of producing any intermediate byte-arrays (and the scanning)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2015
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2016
    (aSmallInteger == 0) ifTrue: [
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2017
	digitByteArray := ByteArray with:0.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2018
	sign := 0.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2019
	^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2020
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  2021
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2022
    (aSmallInteger < 0) ifTrue: [
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2023
	sign := -1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2024
	absValue := aSmallInteger negated
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2025
    ] ifFalse: [
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2026
	sign := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2027
	absValue := aSmallInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2028
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  2029
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2030
    b1 := absValue bitAnd:16rFF.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2031
    absValue := absValue bitShift:-8.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2032
    absValue == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2033
	digitByteArray := ByteArray with:b1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2034
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2035
	b2 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2036
	absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2037
	absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2038
	    digitByteArray := ByteArray with:b1 with:b2
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2039
	] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2040
	    b3 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2041
	    absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2042
	    absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2043
		digitByteArray := ByteArray with:b1 with:b2 with:b3
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2044
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2045
		b4 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2046
		absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2047
		absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2048
		    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2049
		] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2050
		    b5 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2051
		    absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2052
		    absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2053
			digitByteArray := ByteArray new:5.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2054
			digitByteArray at:1 put:b1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2055
			digitByteArray at:2 put:b2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2056
			digitByteArray at:3 put:b3.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2057
			digitByteArray at:4 put:b4.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2058
			digitByteArray at:5 put:b5.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2059
		    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2060
			b6 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2061
			absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2062
			absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2063
			    digitByteArray := ByteArray new:6.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2064
			    digitByteArray at:1 put:b1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2065
			    digitByteArray at:2 put:b2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2066
			    digitByteArray at:3 put:b3.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2067
			    digitByteArray at:4 put:b4.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2068
			    digitByteArray at:5 put:b5.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2069
			    digitByteArray at:6 put:b6.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2070
			] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2071
			    b7 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2072
			    absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2073
			    absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2074
				digitByteArray := ByteArray new:7.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2075
				digitByteArray at:1 put:b1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2076
				digitByteArray at:2 put:b2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2077
				digitByteArray at:3 put:b3.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2078
				digitByteArray at:4 put:b4.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2079
				digitByteArray at:5 put:b5.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2080
				digitByteArray at:6 put:b6.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2081
				digitByteArray at:7 put:b7.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2082
			    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2083
				digitByteArray := ByteArray new:8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2084
				digitByteArray at:1 put:b1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2085
				digitByteArray at:2 put:b2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2086
				digitByteArray at:3 put:b3.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2087
				digitByteArray at:4 put:b4.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2088
				digitByteArray at:5 put:b5.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2089
				digitByteArray at:6 put:b6.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2090
				digitByteArray at:7 put:b7.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2091
				digitByteArray at:8 put:absValue.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2092
			    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2093
			]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2094
		    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2095
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2096
	    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2097
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2098
    ]
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2099
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2100
    "Modified: / 26.5.1999 / 22:18:14 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2101
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2102
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2103
!LargeInteger methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2104
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2105
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2106
    "return true, if the argument, aNumber is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2107
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2108
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2109
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2110
    (aNumber class == self class) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2111
	otherSign := aNumber sign.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2112
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2113
	(sign > 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2114
	    "I am positive"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2115
	    (otherSign > 0) ifTrue:[^ self absLess:aNumber].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2116
	    ^ false "aNumber is <= 0"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2117
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2118
	"I am negative"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2119
	(otherSign > 0) ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2120
	(otherSign == 0) ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2121
	^ (aNumber absLess:self)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2122
    ].
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2123
    (aNumber class == SmallInteger) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2124
	otherSign := aNumber sign.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2125
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2126
	(sign > 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2127
	    "I am positive"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2128
	    ^ false "aNumber is <= 0"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2129
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2130
	(sign == 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2131
	    (otherSign > 0) ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2132
	    ^ false
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2133
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2134
	"I am negative"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2135
	^ true
14766
ae12897bef55 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 13992
diff changeset
  2136
    ].
ae12897bef55 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 13992
diff changeset
  2137
    "/ hack for epsilon tests
ae12897bef55 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 13992
diff changeset
  2138
    (aNumber class == Float) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2139
	self negative ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2140
	    "/ I am a large negative; so my value is definitely below SmallInteger minVal
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2141
	    aNumber >= SmallInteger minVal asFloat ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2142
	] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2143
	    "/ I am a large positive; so my value is definitely above SmallInteger maxVal
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2144
	    aNumber <= SmallInteger maxVal asFloat ifTrue:[^ false].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2145
	].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2146
    ].
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2147
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2148
    ^ aNumber lessFromInteger:self
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  2149
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  2150
    "Modified: / 31.7.2002 / 10:08:19 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2151
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2152
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2153
= aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  2154
    "return true, if the argument represents the same numeric value
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  2155
     as the receiver, false otherwise"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2156
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2157
    "/ speed up compare to 0
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2158
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  2159
    (aNumber == 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2160
	^ sign == 0
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2161
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2162
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2163
    (aNumber class == self class) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2164
	"/
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2165
	"/ here, we depend on the fact, that largeinteger
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2166
	"/ results are always converted to smallInts, if possible.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2167
	"/ therefore, a largeInt in the smallInt range is not allowed (possible)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2168
	"/
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2169
	aNumber class == SmallInteger ifTrue:[^ false ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2170
	^ aNumber equalFromInteger:self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2171
    ].
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  2172
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2173
    (aNumber sign == sign) ifFalse:[^ false].
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2174
    ^ digitByteArray = aNumber digitBytes "/ ^ self absEq:aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2175
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2176
    "Modified: / 13.2.1998 / 11:43:15 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2177
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2178
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2179
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2180
    "return true, if the argument, aNumber is less than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2181
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2182
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2183
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2184
    (aNumber class == self class) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2185
	^ (aNumber < self)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2186
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2187
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2188
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2189
    (sign > 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2190
	"I am positive"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2191
	(otherSign > 0) ifTrue:[^ aNumber absLess:self].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2192
	^ true "aNumber is <= 0"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2193
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2194
    (sign == 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2195
	"I am zero"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2196
	(otherSign > 0) ifTrue:[^ false].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2197
	^ true
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2198
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2199
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2200
    (otherSign > 0) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2201
    (otherSign == 0) ifTrue:[^ false].
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  2202
    ^ (self absLess:aNumber)
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  2203
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  2204
    "Modified: / 31.7.2002 / 10:08:59 / cg"
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  2205
!
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  2206
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  2207
hash
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  2208
    "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
  2209
19555
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2210
    |sz h|
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2211
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2212
    sz := digitByteArray size.
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2213
    (sz <= SmallInteger maxBytes and:[self absLess:SmallInteger maxVal]) ifTrue:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  2214
	"I am really an unnormalized SmallInteger, answer the same hash as for the SmallInteger"
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  2215
	^ self bitAnd:SmallInteger maxVal.
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2216
    ].
19555
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2217
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2218
    h := digitByteArray computeXorHashFrom:1 to:8.                  "/ the low 8 bytes
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2219
    sz > 8 ifTrue:[                                                 "/ the high 8 bytes
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  2220
	h := h bitXor:(digitByteArray computeXorHashFrom:sz-8 to:sz).
19555
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2221
    ].
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2222
    ^ h
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2223
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2224
    "
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  2225
     16r80000000 hash
19555
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2226
     16r-80000000 asLargeInteger hash
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  2227
     16r80000008 hash
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  2228
     16r8000000000008 hash
19555
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2229
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2230
     16r8000000000000000 hash
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2231
     16r8000000000000008 hash
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2232
     16r800000000000000000008 hash
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2233
     16r-800000000000000000008 hash
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2234
    "
17246
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2235
!
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2236
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2237
hashMultiply
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2238
    "used in some squeak code to generate an alternative hash value for integers"
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2239
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2240
    "Truncate to 28 bits and try again"
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2241
    ^(self bitAnd: 16rFFFFFFF) hashMultiply
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2242
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2243
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2244
!LargeInteger methodsFor:'double dispatching'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2245
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2246
differenceFromInteger:anInteger
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2247
    "sent, when anInteger does not know how to subtract the receiver.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2248
     Return the result of 'anInteger - self'. The argument must be a SmallInteger."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2249
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2250
    anInteger > 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2251
	sign > 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2252
	    ^ self absFastMinus:anInteger sign:-1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2253
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2254
	^ self absFastPlus:anInteger sign:1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2255
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2256
    anInteger == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2257
	^ self negated
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2258
    ].
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2259
    sign > 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2260
	^ self absFastPlus:anInteger negated sign:-1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2261
    ].
10728
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2262
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2263
    self > anInteger ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2264
	^ self absFastMinus:anInteger asLargeInteger sign:-1
10728
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2265
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2266
	^ anInteger asLargeInteger absFastMinus:self sign:-1
10728
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2267
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2268
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2269
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2270
     12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2271
     -12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2272
     12345678901234567890 differenceFromInteger:0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2273
     12345678901234567890 differenceFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2274
     12345678901234567890 differenceFromInteger:-1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2275
     -12345678901234567890 differenceFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2276
     -12345678901234567890 differenceFromInteger:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2277
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2278
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2279
    "Modified: 20.10.1996 / 18:41:54 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2280
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2281
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2282
equalFromInteger:anInteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2283
    "sent when an integer does not know how to compare to the receiver, a largeInt"
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2284
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  2285
    |otherClass|
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2286
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2287
    "/
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2288
    "/ here, we depend on the fact, that largeinteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2289
    "/ results are always converted to smallInts, if possible.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2290
    "/ therefore, a largeInt in the smallInt range is not allowed (possible)
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2291
    "/
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  2292
    otherClass := anInteger class.
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  2293
    otherClass == SmallInteger ifTrue:[^ false ].
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  2294
    otherClass == self class ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2295
	(anInteger sign == sign) ifFalse:[^ false].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2296
	^ self absEq:anInteger
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2297
    ].
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  2298
    ^ super equalFromInteger:anInteger
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2299
!
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2300
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2301
lessFromInteger:anInteger
18855
85ed6541937d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18848
diff changeset
  2302
    "sent when an integer does not know how to compare to the receiver, a largeInt.
85ed6541937d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18848
diff changeset
  2303
     Return true if anInteger < self"
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2304
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2305
    "/
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2306
    "/ here, we depend on the fact, that largeinteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2307
    "/ results are always converted to smallInts, if possible.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2308
    "/ therefore, a largeInt in the smallInt range is not allowed (possible)
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2309
    "/
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2310
    (anInteger class == SmallInteger) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2311
	(sign > 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2312
	    "I am positive - any largeInteger is larger than any smallInteger"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2313
	    ^ true "anInteger is <= 0"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2314
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2315
	"I am negative - any negative largeInteger is smaller than any smallInteger"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2316
	^ false
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2317
    ].
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2318
    ^ super lessFromInteger:anInteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2319
!
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2320
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2321
productFromInteger:anInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2322
    "sent, when anInteger does not know how to multiply the receiver.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2323
     Return the product of the receiver and the argument, aSmallInteger"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2324
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2325
    |num result
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2326
     resultDigitByteArray
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2327
     val     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2328
     len     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2329
     carry   "{ Class: SmallInteger }"
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2330
     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
  2331
     ok lResult|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2332
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2333
    "multiplying by a small integer is done here"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2334
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2335
    "trivial cases"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2336
    anInteger == 0 ifTrue:[^ 0].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2337
    anInteger == 1 ifTrue:[^ self].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2338
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2339
    num := anInteger abs.
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  2340
    SmallInteger maxBytes == 8 ifTrue:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2341
        (num > 16rFFFFFFFFFF) ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2342
            "if num is too big (so that multiplying by a byte could create a Large)"
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2343
            ^ anInteger retry:#* coercing:self
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2344
        ].
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2345
    ] ifFalse:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2346
        (num > 16r3FFFFF) ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2347
            "if num is too big (so that multiplying by a byte could create a Large)"
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2348
            ^ anInteger retry:#* coercing:self
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2349
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2350
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2351
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2352
    len := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2353
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2354
    val := num.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  2355
    val <= 16rFF ifTrue:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2356
        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
  2357
    ] ifFalse:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2358
        val <= 16rFFFF ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2359
            lResult := len + 2
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2360
        ] ifFalse:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2361
            val <= 16rFFFFFF ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2362
                lResult := len + 4.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2363
            ] ifFalse:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2364
                val <= 16rFFFFFFFF ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2365
                    lResult := len + 6.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2366
                ] ifFalse:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2367
                    val <= 16rFFFFFFFFFF ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2368
                        lResult := len + 8.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2369
                    ] ifFalse:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2370
                        val <= 16rFFFFFFFFFF ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2371
                            lResult := len + 10.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2372
                        ] ifFalse:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2373
                            val <= 16rFFFFFFFFFFFF ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2374
                                lResult := len + 12.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2375
                            ] ifFalse:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2376
                                lResult := len + 14.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2377
                            ]
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2378
                        ]
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2379
                    ]
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2380
                ]
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2381
            ]
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2382
        ]
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2383
    ].
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  2384
    resultDigitByteArray := ByteArray uninitializedNew:lResult.
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2855
diff changeset
  2385
    result := self class basicNew setDigits:resultDigitByteArray.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2386
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2387
    anInteger < 0 ifTrue:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2388
        sign > 0 ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2389
            result setSign:-1
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2390
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2391
    ] ifFalse:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2392
        sign < 0 ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2393
            result setSign:sign
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2394
        ]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2395
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2396
85
claus
parents: 77
diff changeset
  2397
    ok := false.
claus
parents: 77
diff changeset
  2398
%{
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2399
    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
  2400
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2401
    if (__isSmallInteger(len)
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2402
     && __isByteArray(__digitByteArray)
85
claus
parents: 77
diff changeset
  2403
     && __isByteArray(resultDigitByteArray)) {
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2404
        INT _l = __intVal(len);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2405
        INT _v = __intVal(val);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2406
        unsigned INT _carry = 0;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2407
        unsigned INT _prod;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2408
        unsigned char *digitP = __ByteArrayInstPtr(__digitByteArray)->ba_element;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2409
        unsigned char *resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2410
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2411
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2412
         * skipping zeros does not help much (a few percent) on
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2413
         * a P5 or other CPUS with a fast multiplier.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2414
         * It may make more of a difference on CPUs with slower 0-multiply.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2415
         * Late news: it actually hurts modern x86_64 cpus.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2416
         * So only reenable for specific CPUs after concrete benchmarks.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2417
         */
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  2418
#if 0
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2419
        while ((_l >= sizeof(INT)) && (((unsigned INT *)digitP)[0] == 0)) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2420
            ((unsigned INT *)resultP)[0] = 0;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2421
            digitP += sizeof(INT);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2422
            resultP += sizeof(INT);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2423
            _l -= sizeof(INT);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2424
        }
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  2425
#endif
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  2426
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2427
#if defined(__LSBFIRST__)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2428
# if defined (__GNUC__) && defined(__i386__) && (__POINTER_SIZE__ == 4)
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2429
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2430
         * can do it long-word-wise;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2431
         * 32*32 -> 64 multiplication
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2432
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2433
        while (_l > 3) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2434
            unsigned __pHi, __pLow;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2435
            unsigned __digit;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2436
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2437
            /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2438
             * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2439
             * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2440
             */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2441
            __digit = ((unsigned long *)digitP)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2442
            asm ("mull %3               \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2443
                  addl %4,%%eax         \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2444
                  adcl $0,%%edx"
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2445
                    : "=a"  (__pLow),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2446
                      "=d"  (__pHi)
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2447
                    : "0"   (__digit),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2448
                      "1"   (ASM_ULONGCAST(_v)),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2449
                      "rm"  (ASM_ULONGCAST(_carry)) );
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2450
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2451
            ((unsigned long *)resultP)[0] = __pLow;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2452
            _carry = __pHi;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2453
            digitP += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2454
            resultP += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2455
            _l -= 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2456
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2457
# else /* not GNU-i386 */
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  2458
#  if defined(__win32__) && defined(__BORLANDC__) && defined(__x86__) && (__POINTER_SIZE__ == 4)
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2459
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2460
         * can do it long-word-wise;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2461
         * 32*32 -> 64 multiplication
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2462
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2463
        while (_l > 3) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2464
            unsigned __pLow;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2465
            unsigned digit;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2466
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2467
            /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2468
             * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2469
             * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2470
             */
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  2471
/*
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2472
            digit = ((unsigned long *)digitP)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2473
            edx::eax = (digit * _v);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2474
            edx::eax += _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2475
            ((unsigned long *)resultP)[0] = eax; -- pLow
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2476
            _carry = edx; -- pHigh
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2477
            digitP += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2478
            resultP += 4;
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  2479
*/
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2480
            digit = ((unsigned long *)digitP)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2481
            asm {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2482
                mov   eax, digit
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2483
                mov   edx, _v
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2484
                mul   edx
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2485
                add   eax, _carry
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2486
                adc   edx, 0
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2487
                mov   __pLow, eax
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2488
                mov   _carry, edx
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2489
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2490
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2491
            ((unsigned long *)resultP)[0] = __pLow;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2492
            digitP += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2493
            resultP += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2494
            _l -= 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2495
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2496
#  else /* not WIN32-i386 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2497
#   if defined(INT64)
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2498
        if (_v <= 0xFFFFFFFFL) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2499
            /* have 64bit ints; can do it int-wise
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2500
             *
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2501
             * max: 0xFFFFFFFF * 0xFFFFFFFF -> 0xFFFFFFFE.0001
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2502
             * + maxCarry (0xFFFFFFFF)  -> 0xFFFFFFFF.0000
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2503
             */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2504
            while (_l >= (4+4+4+4)) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2505
                unsigned __t1, __t2, __t3, __t4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2506
                UINT64 _prod64a, _prod64b, _prod64c, _prod64d;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2507
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2508
                __t1 = ((unsigned *)digitP)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2509
                _prod64a = (INT64)_v;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2510
                _prod64a *= __t1;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2511
                _prod64a += _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2512
                ((unsigned *)resultP)[0] = _prod64a /* & 0xFFFFFFFFL */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2513
                _carry = _prod64a >> 32;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2514
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2515
                __t2 = ((unsigned *)digitP)[1];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2516
                _prod64b = (INT64)_v;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2517
                _prod64b *= __t2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2518
                _prod64b += _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2519
                ((unsigned *)resultP)[1] = _prod64b /* & 0xFFFFFFFFL */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2520
                _carry = _prod64b >> 32;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2521
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2522
                __t3 = ((unsigned *)digitP)[2];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2523
                _prod64c = (INT64)_v;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2524
                _prod64c *= __t3;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2525
                _prod64c += _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2526
                ((unsigned *)resultP)[2] = _prod64c /* & 0xFFFFFFFFL */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2527
                _carry = _prod64c >> 32;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2528
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2529
                __t4 = ((unsigned *)digitP)[3];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2530
                _prod64d = (INT64)_v;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2531
                _prod64d *= __t4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2532
                _prod64d += _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2533
                ((unsigned *)resultP)[3] = _prod64d /* & 0xFFFFFFFFL */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2534
                _carry = _prod64d >> 32;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2535
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2536
                digitP += (4+4+4+4);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2537
                resultP += (4+4+4+4);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2538
                _l -= (4+4+4+4);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2539
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2540
            while (_l >= 4) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2541
                unsigned __t;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2542
                UINT64 _prod64;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2543
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2544
                __t = ((unsigned *)digitP)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2545
                _prod64 = (INT64)_v;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2546
                _prod64 *= __t;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2547
                _prod64 += _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2548
                ((unsigned *)resultP)[0] = _prod64 /* & 0xFFFFFFFFL */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2549
                _carry = _prod64 >> 32;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2550
                digitP += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2551
                resultP += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2552
                _l -= 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2553
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2554
            if (_l >= 2) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2555
                unsigned short __t;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2556
                UINT64 _prod64;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2557
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2558
                __t = ((unsigned short *)digitP)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2559
                _prod64 = (INT64)_v;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2560
                _prod64 *= __t;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2561
                _prod64 += _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2562
                ((unsigned short *)resultP)[0] = _prod64 /* & 0xFFFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2563
                _carry = _prod64 >> 16;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2564
                digitP += 2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2565
                resultP += 2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2566
                _l -= 2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2567
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2568
            if (_l > 0) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2569
                UINT64 _prod64;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2570
                _prod64 = *digitP++ * _v + _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2571
                *resultP++ = _prod64 /* & 0xFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2572
                _carry = _prod64 >> 8;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2573
                _l--;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2574
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2575
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2576
#   else /* no INT64 type */
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2577
        if (_v <= 0xFFFF) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2578
            /* can do it short-wise
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2579
             *
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2580
             * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2581
             * + maxCarry (0xFFFF)  -> 0xFFFF.0000
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2582
             */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2583
            while (_l > 1) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2584
                _prod = ((unsigned short *)digitP)[0] * _v + _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2585
                ((unsigned short *)resultP)[0] = _prod /* & 0xFFFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2586
                _carry = _prod >> 16;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2587
                digitP += 2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2588
                resultP += 2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2589
                _l -= 2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2590
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2591
        }
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2592
#   endif /* no INT64 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2593
#  endif /* not WIN32-i386 */
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  2594
# endif /* not GNU-i386 */
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  2595
#else /* not LSB_FIRST */
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2596
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2597
# ifdef __mips__
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2598
#  define LOAD_WORD_WISE
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2599
   /* 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
  2600
# endif
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2601
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2602
        if (_v <= 0xFFFF) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2603
            /* can do it short-wise
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2604
             *
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2605
             * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2606
             * + maxCarry (0xFFFF)  -> 0xFFFF.0000
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2607
             */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2608
            while (_l > 1) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2609
                unsigned int t;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2610
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2611
#if defined(LOAD_WORD_WISE)
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2612
                /* better fetch short-wise */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2613
                t = ((unsigned short *)digitP)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2614
                digitP += 2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2615
                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
  2616
#else
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2617
                t = (digitP[1]<<8) + digitP[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2618
                digitP += 2;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2619
#endif
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2620
                _prod = t * _v + _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2621
                _carry = _prod >> 16;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2622
#if defined(STORE_WORD_WISE)
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2623
                /* better store short-wise */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2624
                _prod = ((_prod >> 8) | (_prod << 8)) & 0xFFFF;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2625
                ((unsigned short *)resultP)[0] = _prod;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2626
#else
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2627
                resultP[0] = _prod /* & 0xFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2628
                resultP[1] = (_prod>>8) /* & 0xFF */;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2629
#endif
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2630
                resultP += 2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2631
                _l -= 2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2632
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2633
        }
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  2634
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  2635
#endif /* LSB_FIRST */
1797
8dafe47b33fd faster multiplication by an integer.
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
  2636
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2637
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2638
         * rest is done byte-wise
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2639
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2640
        while (_l > 0) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2641
            _prod = *digitP++ * _v + _carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2642
            *resultP++ = _prod /* & 0xFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2643
            _carry = _prod >> 8;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2644
            _l--;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2645
        }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2646
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2647
        _l = __intVal(lResult) - __intVal(len);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2648
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2649
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2650
         * remaining carry
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2651
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2652
        while (_carry) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2653
            *resultP++ = _carry /* & 0xFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2654
            _carry >>= 8;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2655
            _l--;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2656
        }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2657
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2658
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2659
         * remaining zeros
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2660
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2661
        while (_l--) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2662
            *resultP++ = 0;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2663
        }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2664
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2665
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2666
         * need compress ?
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2667
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2668
        if (resultP[-1]) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2669
            /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2670
             * no
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2671
             */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2672
            RETURN(result);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2673
        }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2674
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2675
        ok = true;
85
claus
parents: 77
diff changeset
  2676
    }
claus
parents: 77
diff changeset
  2677
%}.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2678
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2679
     fall back - normally not reached
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2680
     (could make it a primitive-failure as well)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2681
    "
85
claus
parents: 77
diff changeset
  2682
    ok ifFalse:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2683
        carry := 0.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2684
        1 to:len do:[:i |
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2685
            prod := (digitByteArray basicAt:i) * val + carry.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2686
            resultDigitByteArray basicAt:i put:(prod bitAnd:16rFF).
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2687
            carry := prod bitShift:-8.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2688
        ].
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2689
        [carry ~~ 0] whileTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2690
            len := len + 1.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2691
            resultDigitByteArray basicAt:len put:(carry bitAnd:16rFF).
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2692
            carry := carry bitShift:-8
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2693
        ].
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2694
        [len < lResult] whileTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2695
            len := len + 1.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2696
            resultDigitByteArray basicAt:len put:0
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  2697
        ]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2698
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2699
    ^ result compressed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2700
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2701
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2702
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2703
    "sent, when anInteger does not know how to add the receiver.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2704
     Return the sum of the receiver and the argument, (which must be a SmallInteger)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2705
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2706
    anInteger > 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2707
	sign > 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2708
	    ^ self absFastPlus:anInteger sign:1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2709
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2710
	^ self absFastMinus:anInteger sign:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2711
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2712
    anInteger == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2713
	^ self
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2714
    ].
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2715
    sign > 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2716
	^ self absFastMinus:anInteger sign:1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2717
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2718
    ^ self absFastPlus:anInteger sign:-1
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2719
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2720
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2721
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2722
     12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2723
     -12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2724
     12345678901234567890 sumFromInteger:0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2725
     -12345678901234567890 sumFromInteger:0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2726
     12345678901234567890 sumFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2727
     12345678901234567890 sumFromInteger:-1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2728
     -12345678901234567890 sumFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2729
     -12345678901234567890 sumFromInteger:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2730
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2731
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2732
    "Modified: / 9.1.1998 / 13:27:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2733
! !
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2734
15577
cc63cd495a01 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15569
diff changeset
  2735
!LargeInteger methodsFor:'modulo arithmetic'!
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2736
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2737
plus32:aNumber
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2738
    "return the sum of the receiver and the argument, as SmallInteger.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2739
     The argument must be another SmallInteger.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2740
     If the result overflows the 32 bit range, the value modulo 16rFFFFFFFF is returned.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2741
     This is of course not always correct, but allows for C/Java behavior to be emulated."
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2742
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2743
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2744
    INT sum;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2745
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2746
    sum =  __unsignedLongIntVal(self) + __unsignedLongIntVal(aNumber);
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2747
#if __POINTER_SIZE__ == 8
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2748
    sum &= 0xFFFFFFFFL;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2749
#endif
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2750
    RETURN ( __MKUINT(sum));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2751
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2752
    self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2753
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2754
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2755
     16r7FFFFFFF + 1       ->  2147483648
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  2756
     16r7FFFFFFF plus32: 1 ->  -2147483648
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2757
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2758
! !
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2759
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2760
!LargeInteger methodsFor:'printing & storing'!
345
claus
parents: 250
diff changeset
  2761
5682
a1a516779f72 remove storeOn: use insteat the default printString
ca
parents: 5437
diff changeset
  2762
xxxstoreOn:aStream
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2763
    "append a representation of the receiver to aStream, which can
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2764
     be used to reconstruct the receiver."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2765
5682
a1a516779f72 remove storeOn: use insteat the default printString
ca
parents: 5437
diff changeset
  2766
    aStream nextPutAll:'('.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2767
    self printOn:aStream.
5954
d706efecb134 ZeroDivide has a parameter
Claus Gittinger <cg@exept.de>
parents: 5682
diff changeset
  2768
    aStream nextPutAll:' asLargeInteger)'
d706efecb134 ZeroDivide has a parameter
Claus Gittinger <cg@exept.de>
parents: 5682
diff changeset
  2769
! !
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2770
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2771
!LargeInteger methodsFor:'private'!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2772
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2773
absDestructiveSubtract:aLargeInteger
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2774
    "private helper for division:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2775
	destructively subtract aLargeInteger from myself
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2776
	AND return true, if the result is non-zero, false otherwise.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2777
	(i.e. this method has both a return value and a side-effect on the receiver)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2778
	Does not care about the signs of the receiver and argument
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2779
	The receiver must be >= the argument.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2780
	The receiver must be a temporary scratch-number"
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2781
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2782
    |otherDigitByteArray
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2783
     len1   "{ Class: SmallInteger }"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2784
     len2   "{ Class: SmallInteger }"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2785
     index  "{ Class: SmallInteger }"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2786
     borrow "{ Class: SmallInteger }"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2787
     diff   "{ Class: SmallInteger }"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2788
     notZero
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2789
    |
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2790
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2791
    notZero := false.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2792
    len1 := digitByteArray size.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2793
    otherDigitByteArray := aLargeInteger digitBytes.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2794
    len2 := otherDigitByteArray size.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2795
    len2 > len1 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2796
	[(otherDigitByteArray at:len2) == 0] whileTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2797
	    len2 := len2 - 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2798
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2799
	len2 > len1 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2800
	    self error:'operation failed' "/ may not be called that way
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2801
	].
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2802
    ].
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2803
    "/ knowing that len2 is <= len1
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2804
%{
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2805
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2806
    OBJ _digitByteArray = __INST(digitByteArray);
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2807
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2808
    if (__isByteArray(_digitByteArray)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2809
     && __isByteArray(otherDigitByteArray)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2810
	int _len1 = __intVal(len1),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2811
	    _len2 = __intVal(len2);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2812
	unsigned char *_myDigits, *_otherDigits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2813
	int _index = 1, _borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2814
	INT _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2815
	int anyBitNonZero = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2816
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2817
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2818
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2819
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2820
#if defined(__LSBFIRST__)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2821
# if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2822
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2823
	    int _len2Q;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2824
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2825
	     * subtract int-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2826
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2827
	    _len2Q = _len2-4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2828
	    while (_index <= _len2Q) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2829
		/* do not combine the expression below (may lead to unsigned result on some machines) */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2830
		_diff = ((unsigned int *)(_myDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2831
		_diff -= ((unsigned int *)(_otherDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2832
		_diff -= _borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2833
		if (_diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2834
		    _borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2835
		} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2836
		    _borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2837
		    /* _diff += 0x100000000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2838
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2839
		((unsigned int *)(_myDigits+_index-1))[0] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2840
		anyBitNonZero |= (_diff & 0xFFFFFFFFL);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2841
		_index += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2842
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2843
	}
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2844
# endif
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2845
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2846
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2847
	 * subtract short-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2848
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2849
	while (_index < _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2850
	    /* do not combine the expression below (may lead to unsigned result on some machines */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2851
	    _diff = ((unsigned short *)(_myDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2852
	    _diff -= ((unsigned short *)(_otherDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2853
	    _diff -= _borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2854
	    if (_diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2855
		_borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2856
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2857
		_borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2858
		/* _diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2859
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2860
	    ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2861
	    anyBitNonZero |= (_diff & 0xFFFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2862
	    _index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2863
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2864
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2865
	if (_index <= _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2866
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2867
	     * cannot continue with shorts - there is an odd number of
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2868
	     * bytes in the minuent
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2869
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2870
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2871
	    while (_index < _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2872
		/* do not combine the expression below (may lead to unsigned result on some machines */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2873
		_diff = ((unsigned short *)(_myDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2874
		_diff -= _borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2875
		if (_diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2876
		    /* _borrow = 0; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2877
		    ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2878
		    anyBitNonZero |= (_diff & 0xFFFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2879
		    _index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2880
		    while (_index < _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2881
			anyBitNonZero |= ((unsigned short *)(_myDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2882
			if (anyBitNonZero) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2883
			    RETURN (true);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2884
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2885
			_index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2886
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2887
		    /* last odd index */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2888
		    if (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2889
			anyBitNonZero |= _myDigits[_index - 1];;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2890
			if (anyBitNonZero) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2891
			    RETURN (true);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2892
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2893
			_index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2894
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2895
		    RETURN (anyBitNonZero ? true : false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2896
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2897
		_borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2898
		/* _diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2899
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2900
		((unsigned short *)(_myDigits+_index-1))[0] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2901
		anyBitNonZero |= (_diff & 0xFFFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2902
		_index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2903
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2904
	}
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2905
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2906
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2907
	 * subtract byte-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2908
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2909
	while (_index <= _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2910
	    /* do not combine the expression below (may lead to unsigned result on some machines */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2911
	    _diff = _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2912
	    _diff -= _otherDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2913
	    _diff -= _borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2914
	    if (_diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2915
		_borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2916
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2917
		_borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2918
		/* _diff += 0x100; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2919
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2920
	    _myDigits[_index - 1] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2921
	    anyBitNonZero |= (_diff & 0xFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2922
	    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2923
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2924
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2925
	while (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2926
	    /* do not combine the expression below (may lead to unsigned result on some machines */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2927
	    _diff = _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2928
	    _diff -= _borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2929
	    if (_diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2930
		/* _borrow = 0; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2931
		_myDigits[_index - 1] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2932
		anyBitNonZero |= (_diff & 0xFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2933
		_index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2934
		while (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2935
		    anyBitNonZero |= _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2936
		    if (anyBitNonZero) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2937
			RETURN (true);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2938
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2939
		    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2940
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2941
		break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2942
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2943
	    _borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2944
	    /* _diff += 0x100; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2945
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2946
	    _myDigits[_index - 1] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2947
	    anyBitNonZero |= (_diff & 0xFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2948
	    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2949
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2950
	RETURN (anyBitNonZero ? true : false);
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2951
    }
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2952
%}.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2953
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2954
    index := 1.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2955
    borrow := 0.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2956
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2957
    [index <= len1] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2958
	diff := borrow.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2959
	diff := diff + (digitByteArray basicAt:index).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2960
	index <= len2 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2961
	    diff := diff - (otherDigitByteArray basicAt:index).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2962
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2963
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2964
	"/ workaround for gcc code generator bug
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2965
	(diff >= 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2966
	    borrow := 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2967
	] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2968
	    borrow := -1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2969
	    diff := diff + 16r100
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2970
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2971
	diff ~~ 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2972
	    notZero := true
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2973
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2974
	digitByteArray basicAt:index put:diff.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2975
	index := index + 1
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2976
    ].
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2977
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2978
    ^ notZero
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2979
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2980
    "Created: / 5.11.1996 / 16:23:47 / cg"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2981
    "Modified: / 5.11.1996 / 18:56:50 / cg"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2982
    "Modified: / 27.4.1999 / 18:08:23 / stefan"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2983
!
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2984
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2985
absDivMod:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2986
    "return an array with two LargeIntegers representing
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2987
     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
  2988
     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
  2989
     This method needs a rewrite."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2990
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2991
    |dividend divisor
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2992
     quo digits
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2993
     divModOrNil
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2994
     shift "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2995
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2996
    anInteger == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2997
	^ ZeroDivide raiseRequestWith:thisContext
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2998
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2999
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3000
    anInteger class == SmallInteger ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3001
	divisor := anInteger abs.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3002
	divModOrNil := self absFastDivMod:divisor.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3003
	divModOrNil notNil ifTrue:[^ divModOrNil].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3004
	divisor := divisor asLargeInteger.
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3005
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3006
	self = anInteger ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3007
	    ^ Array with:1 with:0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3008
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3009
	divisor := anInteger.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3010
    ].
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3011
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3012
    shift := self highBit - divisor highBit.
16124
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  3013
    dividend := self class digitBytes:digitByteArray copy. "/ self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3014
    shift < 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3015
	^ Array with:0 with:dividend compressed.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3016
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3017
    shift == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3018
	divisor := self class digitBytes:(divisor digitBytes copy). "/ anInteger simpleDeepCopy.
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3019
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3020
	divisor := divisor bitShift:shift.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3021
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3022
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3023
    quo := self class basicNew numberOfDigits:((shift // 8) + 1).
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3024
    digits := quo digitBytes.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3025
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3026
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3027
    [shift > 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3028
	(dividend absLess:divisor) ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3029
	    digits bitSetAt:shift.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3030
	    (dividend absDestructiveSubtract: divisor) ifFalse:[ "result == 0"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3031
		^ Array with:quo compressed with:0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3032
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3033
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3034
	shift := shift - 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3035
	divisor := divisor div2.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3036
    ].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3037
    ^ 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
  3038
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3039
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3040
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:4000000000] ]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3041
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:3000000000] ]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3042
     16000000000 absDivMod:4000000000
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3043
     16000000000 absDivMod:3000000000
19126
98adb7dc1950 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19102
diff changeset
  3044
     160000000000000000000000 absDivMod:160000000000000000000000
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3045
    "
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3046
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3047
    "Modified: / 5.11.1996 / 18:40:24 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3048
    "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
  3049
    "Modified: / 26.7.1999 / 10:46:36 / stefan"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3050
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3051
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3052
absEq:aLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3053
    "return true, if abs(self) = abs(theArgument)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3054
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3055
    |len1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3056
     len2 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3057
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3058
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3059
     otherDigitByteArray |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3060
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3061
%{  /* NOCONTEXT */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3062
    if (__isLargeInteger(aLargeInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3063
	OBJ _digitByteArray = __INST(digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3064
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3065
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3066
	if (__isByteArray(_digitByteArray)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3067
	 && __isByteArray(_otherDigitByteArray)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3068
	    INT _myLen = __byteArraySize(_digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3069
	    INT _otherLen = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3070
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3071
	    unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3072
	    unsigned char *_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3073
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3074
	    if (_myLen == _otherLen) {
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3075
tryAgain:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3076
		while (_myLen >= (sizeof(INT)*4)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3077
		    if ( ((unsigned INT *)_myDigits)[0] != ((unsigned INT *)_otherDigits)[0]) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3078
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3079
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3080
		    if ( ((unsigned INT *)_myDigits)[1] != ((unsigned INT *)_otherDigits)[1]) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3081
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3082
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3083
		    if ( ((unsigned INT *)_myDigits)[2] != ((unsigned INT *)_otherDigits)[2]) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3084
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3085
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3086
		    if ( ((unsigned INT *)_myDigits)[3] != ((unsigned INT *)_otherDigits)[3]) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3087
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3088
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3089
		    _myDigits += sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3090
		    _otherDigits += sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3091
		    _myLen -= sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3092
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3093
		while (_myLen >= (sizeof(INT))) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3094
		    if ( *(unsigned INT *)_myDigits != *(unsigned INT *)_otherDigits) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3095
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3096
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3097
		    _myDigits += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3098
		    _otherDigits += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3099
		    _myLen -= sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3100
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3101
		while (_myLen > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3102
		    if ( *_myDigits != *_otherDigits) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3103
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3104
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3105
		    _myDigits++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3106
		    _otherDigits++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3107
		    _myLen--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3108
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3109
		RETURN(true);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3110
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3111
	    /* care for unnormalized ints */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3112
	    while ((_myLen > 0) && (_myDigits[_myLen-1] == 0)) _myLen--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3113
	    while ((_otherLen > 0) && (_otherDigits[_otherLen-1] == 0)) _otherLen--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3114
	    if (_myLen == _otherLen) goto tryAgain;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3115
	    RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3116
	}
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3117
    }
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3118
%}.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3119
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3120
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3121
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3122
    len2 := otherDigitByteArray size.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3123
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3124
    "/ the highest digit(s) should not be zero
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3125
    "/ when properly normalized;
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3126
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3127
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3128
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3129
    [(digitByteArray basicAt:len1) == 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3130
	len1 := len1 - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3131
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3132
    [(otherDigitByteArray basicAt:len2) == 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3133
	len2 := len2 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3134
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3135
    (len1 ~~ len2) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3136
    [len1 > 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3137
	d1 := digitByteArray basicAt:len1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3138
	d2 := otherDigitByteArray basicAt:len1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3139
	(d1 ~~ d2) ifTrue:[^ false].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3140
	len1 := len1 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3141
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3142
    ^ true
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3143
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3144
    "Modified: / 8.5.1999 / 18:37:02 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3145
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3146
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3147
absFastDivMod:aPositiveSmallInteger
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3148
    "return an array with two LargeIntegers representing
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3149
	abs(self) // aPositiveSmallInteger and
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3150
	abs(self) \\ aPositiveSmallInteger
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3151
     or nil, if not computed by optimized code"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3152
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3153
    |tmp1     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3154
     prevRest "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3155
     count    "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  3156
     newDigitByteArray result
claus
parents: 77
diff changeset
  3157
     ok|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3158
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3159
    aPositiveSmallInteger == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3160
	^ ZeroDivide raiseRequestWith:thisContext
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3161
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3162
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3163
"This cannot happen (if always normalized)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3164
    self < aPositiveSmallInteger ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3165
	^ Array with:0 with:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3166
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3167
"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3168
    count := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3169
    result := self class basicNew numberOfDigits:count.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3170
    newDigitByteArray := result digitBytes.
85
claus
parents: 77
diff changeset
  3171
    ok := false.
claus
parents: 77
diff changeset
  3172
%{
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  3173
    OBJ __digits;
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  3174
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  3175
    __digits = __INST(digitByteArray);
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  3176
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  3177
    if (__isByteArray(__digits)
85
claus
parents: 77
diff changeset
  3178
     && __isByteArray(newDigitByteArray)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3179
     && __bothSmallInteger(count, aPositiveSmallInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3180
	unsigned INT rest = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3181
	int index = __intVal(count);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3182
	int index0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3183
	unsigned INT divisor = __intVal(aPositiveSmallInteger);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3184
	unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3185
	unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3186
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3187
	index0 = index - 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3188
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3189
	// at least one byte of value must remain when dividing
19256
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3190
# if (__POINTER_SIZE__ == 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3191
	if (divisor > 0xFFFFFFFFFFFFFF) RETURN(nil);
19256
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3192
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3193
	if (divisor > 0xFFFFFF) RETURN(nil);
19256
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3194
# endif
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3195
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3196
# if (__POINTER_SIZE__ == 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3197
	if (sizeof(int) == 4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3198
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3199
	     * divide int-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3200
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3201
	    if (divisor <= 0xFFFFFFFF) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3202
		if ((index & 3) == 0) { /* even number of int32's */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3203
		    while (index > 3) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3204
			unsigned INT t;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3205
			unsigned INT div;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3206
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3207
			index -= 4;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3208
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3209
			t = *((unsigned int *)(&digitBytes[index]));
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3210
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3211
			t = digitBytes[index+3];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3212
			t = (t << 8) | digitBytes[index+2];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3213
			t = (t << 8) | digitBytes[index+1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3214
			t = (t << 8) | digitBytes[index];
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3215
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3216
			t = t | (rest << 32);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3217
			div = t / divisor;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3218
			rest = t % divisor;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3219
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3220
			*((unsigned int *)(&resultBytes[index])) = (div & 0xFFFFFFFF);
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3221
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3222
			resultBytes[index+3] = div >> 24;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3223
			resultBytes[index+2] = div >> 16;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3224
			resultBytes[index+1] = div >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3225
			resultBytes[index] = div /* & 0xFF */;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3226
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3227
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3228
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3229
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3230
	}
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  3231
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3232
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3233
	 * divide short-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3234
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3235
	if (divisor <= 0xFFFF) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3236
	    if ((index & 1) == 0) { /* even number of bytes */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3237
		while (index > 1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3238
		    unsigned INT t;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3239
		    unsigned INT div;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3240
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3241
		    index -= 2;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3242
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3243
		    t = *((unsigned short *)(&digitBytes[index]));
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3244
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3245
		    t = digitBytes[index+1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3246
		    t = (t << 8) | digitBytes[index];
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3247
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3248
		    t = t | (rest << 16);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3249
		    div = t / divisor;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3250
		    rest = t % divisor;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3251
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3252
		    *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3253
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3254
		    resultBytes[index+1] = div >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3255
		    resultBytes[index] = div /* & 0xFF */;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3256
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3257
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3258
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3259
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3260
	while (index > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3261
	    unsigned INT t;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3263
	    index--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3264
	    t = digitBytes[index];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3265
	    t = t | (rest << 8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3266
	    resultBytes[index] = t / divisor;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3267
	    rest = t % divisor;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3268
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3269
	prevRest = __mkSmallInteger(rest);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3270
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3271
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3272
	 * no need to normalize ?
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3273
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3274
	index = index0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3275
	while ((index >= sizeof(INT)) && (resultBytes[index]==0)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3276
	    index--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3277
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3278
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3279
	if (index == index0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3280
	    if (index > sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3281
		RETURN ( __ARRAY_WITH2(result, prevRest));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3282
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3283
	    if ((index == sizeof(INT))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3284
	     && resultBytes[index0] >= 0x40) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3285
		RETURN ( __ARRAY_WITH2(result, prevRest));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3286
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3287
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3288
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3289
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3290
	 * must compress
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3291
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3292
	ok = true;
85
claus
parents: 77
diff changeset
  3293
    }
claus
parents: 77
diff changeset
  3294
%}.
claus
parents: 77
diff changeset
  3295
    "
claus
parents: 77
diff changeset
  3296
     slow code - not normally reached
claus
parents: 77
diff changeset
  3297
     (could also do a primitiveFailure here)
claus
parents: 77
diff changeset
  3298
    "
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3299
    ok ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3300
	^ Array with:(result compressed) with:prevRest
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3301
    ].
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3302
    ^ nil
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3303
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3304
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3305
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3306
     16r123412341234 asLargeInteger absDivMod:(LargeInteger value:10)
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  3307
     ((16r1234 asLargeInteger absFastDivMod:16rffff) at:2) printStringRadix:16
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3308
     ((16r00123456 asLargeInteger absFastDivMod:16rffffff) at:2) printStringRadix:16
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3309
     ((666666666666666666 asLargeInteger absFastDivMod:16r3))
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3310
     ((1666666666 asLargeInteger absFastDivMod:16r3))
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3311
    "
19256
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3312
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3313
    "Modified: / 26-02-2016 / 19:27:13 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3314
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3315
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  3316
absFastMinus:aSmallInteger sign:newSign
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  3317
    "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
  3318
     with sign: newSign.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  3319
     The result is normalized.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  3320
     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
  3321
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3322
    |result resultDigitByteArray lastDigit ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3323
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3324
     rsltLen "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3325
     index   "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3326
     borrow  "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3327
     diff    "{ Class: SmallInteger }" |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3328
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3329
    "/ the following code only works with
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3330
    "/ 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
  3331
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3332
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3333
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3334
	^ self absMinus:(self class value:aSmallInteger) sign:newSign.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3335
    ].
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3336
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3337
    len := digitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3338
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  3339
    rsltLen := len "+ 1".
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3340
    result := self class basicNew numberOfDigits:rsltLen sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3341
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3342
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3343
    borrow := aSmallInteger abs.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3344
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3345
%{
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3346
    if (__isByteArray(__INST(digitByteArray))
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3347
     && __isByteArray(resultDigitByteArray)) {
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3348
	unsigned INT __borrow = __intVal(borrow);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3349
	INT __diff;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3350
	int __index = 1;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3351
	int __len = __intVal(len);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3352
	unsigned char *__digitP = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3353
	unsigned char *__resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3354
	int __len3;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  3355
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3356
#if defined(__LSBFIRST__)
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3357
# if (__POINTER_SIZE__ == 8)
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3358
	/*
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3359
	 * subtract int-wise
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3360
	 */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3361
	__len3 = __len - 3;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3362
	while (__index < __len3) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3363
	    /* do not make this into one expression - ask cg why */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3364
	    __diff = ((unsigned int *)(__digitP + __index-1))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3365
	    __diff -= (__borrow & 0xFFFFFFFFL);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3366
	    __borrow >>= 32;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3367
	    ((unsigned int *)(__resultP+__index-1))[0] = __diff;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3368
	    __index += 4;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3369
	    if (__diff < 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3370
		/* __diff += 0x100000000; */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3371
		__borrow++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3372
	    } else {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3373
		if (__borrow == 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3374
		    /* nothing more to subtract .. */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3375
		    while (__index < __len3) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3376
			((unsigned int *)(__resultP+__index-1))[0] = ((unsigned int *)(__digitP+__index-1))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3377
			__index += 4;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3378
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3379
		    if (__index < __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3380
			((unsigned short *)(__resultP+__index-1))[0] = ((unsigned short *)(__digitP+__index-1))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3381
			__index += 2;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3382
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3383
		    if (__index <= __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3384
			__resultP[__index-1] = __digitP[__index-1];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3385
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3386
		    break;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3387
		}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3388
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3389
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3390
# endif
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3391
	/*
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3392
	 * subtract short-wise
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3393
	 */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3394
	while (__index < __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3395
	    /* do not make this into one expression - ask cg why */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3396
	    __diff = ((unsigned short *)(__digitP+__index-1))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3397
	    __diff -= (__borrow & 0xFFFF);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3398
	    __borrow >>= 16;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3399
	    ((unsigned short *)(__resultP+__index-1))[0] = __diff;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3400
	    __index += 2;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3401
	    if (__diff < 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3402
		/* __diff += 0x10000; */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3403
		__borrow++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3404
	    } else {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3405
		if (__borrow == 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3406
		    /* nothing more to subtract .. */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3407
		    while (__index < __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3408
			((unsigned short *)(__resultP+__index-1))[0] = ((unsigned short *)(__digitP+__index-1))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3409
			__index += 2;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3410
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3411
		    if (__index <= __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3412
			__resultP[__index-1] = __digitP[__index-1];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3413
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3414
		    break;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3415
		}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3416
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3417
	}
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  3418
#endif
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3419
	/*
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3420
	 * subtract byte-wise
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3421
	 */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3422
	while (__index <= __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3423
	    __diff = __digitP[__index-1];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3424
	    __diff -= (__borrow & 0xFF);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3425
	    __borrow >>= 8;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3426
	    __resultP[__index-1] = __diff;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3427
	    __index++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3428
	    if (__diff < 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3429
		/* __diff += 0x100; */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3430
		__borrow++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3431
	    } else {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3432
		if (__borrow == 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3433
		    /* nothing more to subtract .. */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3434
		    while (__index <= __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3435
			__resultP[__index-1] = __digitP[__index-1];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3436
			__index++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3437
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3438
		    break;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3439
		}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3440
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3441
	}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3442
	lastDigit = __mkSmallInteger( __resultP[__index-1-1] );
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3443
	ok = true;
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3444
    }
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3445
%}.
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3446
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  3447
    ok == true ifFalse:[        "/ cannot happen
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3448
	index := 1.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3449
	[borrow ~~ 0] whileTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3450
	    (index <= len) ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3451
		diff := (digitByteArray basicAt:index) - (borrow bitAnd:16rFF).
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3452
		borrow := borrow bitShift:-8.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3453
		diff < 0 ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3454
		    diff := diff + 256.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3455
		    borrow := borrow + 1.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3456
		]
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3457
	    ] ifFalse:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3458
		diff := borrow bitAnd:255.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3459
		borrow := borrow bitShift:-8.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3460
	    ].
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3461
	    resultDigitByteArray basicAt:index put:(lastDigit := diff).
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3462
	    index := index + 1
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3463
	].
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3464
	[index <= len] whileTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3465
	    resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3466
	    index := index + 1
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3467
	].
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3468
	(index <= rsltLen) ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3469
	    lastDigit := 0.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3470
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3471
    ].
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  3472
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3473
    (lastDigit == 0 or:[rsltLen <= SmallInteger maxBytes]) ifTrue:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3474
	^ result compressed.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3475
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3476
    ^ result
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3477
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3478
    "
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3479
     12345678900000000000 absFastMinus:1 sign:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3480
     12345678900000000000 absFastMinus:1 sign:-1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3481
     12345678900000000000 absFastMinus:1000000 sign:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3482
     12345678900000000000 absFastMinus:255 sign:1
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  3483
     (SmallInteger maxVal + 1) absFastMinus:1 sign:1
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3484
     (SmallInteger minVal - 1) absFastMinus:1 sign:1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3485
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  3486
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3487
    "Modified: 24.3.1997 / 21:33:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3488
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3489
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  3490
absFastPlus:aSmallInteger sign:newSign
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3491
    "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
  3492
     with sign: newSign.
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  3493
     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
  3494
     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
  3495
     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
  3496
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  3497
    |result resultDigitByteArray lastDigit
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3498
     ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3499
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3500
     rsltLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3501
     index "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3502
     carry "{ Class: SmallInteger }" |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3503
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3504
    "/ the following code only works with
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3505
    "/ 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
  3506
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3507
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3508
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3509
        ^ self absPlus:(self class value:aSmallInteger) sign:newSign.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3510
    ].
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3511
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3512
    len := rsltLen := digitByteArray size.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3513
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3514
    "/ 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
  3515
    "/ 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
  3516
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3517
    (digitByteArray at:len) == 16rFF ifTrue:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3518
        rsltLen := len + 1.
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  3519
    ] ifFalse:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3520
        "/ or the argument has something in the high byte ..
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  3521
%{
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3522
#if __POINTER_SIZE__ == 8
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3523
        if (__intVal(aSmallInteger) & 0xFF00000000000000L) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3524
            rsltLen = __mkSmallInteger(__intVal(len) + 1);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3525
        }
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  3526
#else
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3527
        if (__intVal(aSmallInteger) & 0xFF000000) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3528
            rsltLen = __mkSmallInteger(__intVal(len) + 1);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3529
        }
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  3530
#endif
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  3531
%}
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3532
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3533
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3534
    result := self class basicNew numberOfDigits:rsltLen sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3535
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3536
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3537
%{
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3538
    if (__isByteArray(__INST(digitByteArray))
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3539
     && __isByteArray(resultDigitByteArray)
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3540
     && __isSmallInteger(aSmallInteger)) {
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3541
        /* carry is NOT unsigned (see negation below) */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3542
        INT __carry = __intVal(aSmallInteger);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3543
        int __index = 1;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3544
        int __len = __intVal(len);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3545
        unsigned char *__src = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3546
        unsigned char *__dst = (unsigned char *)(__ByteArrayInstPtr(resultDigitByteArray)->ba_element);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3547
        INT __ptrDelta = __dst - __src;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3548
        unsigned char *__srcLast = __src + __len - 1;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3549
        int __rsltLen = __intVal(rsltLen);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3550
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3551
        if (__carry < 0) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3552
            __carry = -__carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3553
        }
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  3554
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3555
#if defined(__LSBFIRST__)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3556
# if defined(__i386__) && defined(__GNUC__) && (__POINTER_SIZE__ == 4)
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3557
#  if 0 /* NOTICE - the code below is 20% slower ... - why */
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3558
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3559
         * add long-wise
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3560
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3561
        asm("  jecxz nothingToDo                                      \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3562
               movl  %%eax, %%esi      /* __src input */              \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3563
               movl  %%ebx, %%edi      /* __dst input */              \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3564
                                                                      \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3565
               /* the first 4-byte int */                             \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3566
               lodsl                   /* fetch */                    \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3567
               addl  %%edx, %%eax      /* add */                      \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3568
               stosl                   /* store */                    \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3569
               leal  -1(%%ecx),%%ecx   /* do not clobber carry */     \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3570
               jecxz doneLoop          /* any more ? */               \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3571
               /* remaining 4-byte ints */                            \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3572
               jmp   addLoop                                          \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3573
                                                                      \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3574
               .align 8                                               \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3575
             addLoop:                                                 \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3576
               movl  0(%%esi), %%ebx   /* fetch  */                   \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3577
               jnc   copyLoop2                                        \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3578
               movl  $0, %%eax                                        \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3579
               leal  4(%%esi), %%esi                                  \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3580
               adcl  %%ebx, %%eax      /* & add carry from prev int */\n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3581
               leal  8(%%edi), %%edi                                  \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3582
               movl  %%eax, -8(%%edi)  /* store */                    \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3583
               leal  -1(%%ecx),%%ecx   /* do not clobber carry */     \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3584
               jecxz doneLoop          /* any more ? */               \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3585
                                                                      \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3586
               movl  0(%%esi), %%ebx   /* fetch  */                   \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3587
               movl  $0, %%eax                                        \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3588
               leal  4(%%esi), %%esi                                  \
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3589
               adcl  %%ebx, %%eax      /* & add carry from prev int */\n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3590
               movl  %%eax, -4(%%edi)  /* store */                    \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3591
                                                                      \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3592
               loop  addLoop                                          \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3593
               jmp   doneLoop                                         \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3594
                                                                      \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3595
               .align 8                                               \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3596
             copyLoop:                                                \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3597
               movl  0(%%esi), %%ebx                                  \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3598
             copyLoop2:                                               \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3599
               add   $4, %%esi                                        \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3600
               add   $4, %%edi                                        \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3601
               movl  %%ebx, -4(%%edi)                                 \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3602
               loop  copyLoop                                         \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3603
                                                                      \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3604
             doneLoop:                                                \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3605
               movl  $0, %%edx         /* do not clobber carry (xorl clears it) */   \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3606
               adcl  $0, %%edx                                        \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3607
               movl  %%esi, %%eax      /* __src output */             \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3608
             nothingToDo:                                             \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3609
            " : "=d"  (ASM_ULONGCAST(__carry)),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3610
                "=a"  (__src)
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3611
              : "1"   (__src),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3612
                "b"   (__dst),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3613
                "c"   (__len / 4),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3614
                "0"   (__carry)
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3615
              : "esi", "edi");
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3616
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3617
#  else
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3618
        {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3619
            unsigned char *__srcLastX;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3620
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3621
            __srcLastX = __srcLast - 3 - 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3622
            while (__src <= __srcLastX) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3623
                unsigned int __sum, __sum2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3624
                unsigned __digit1, __digit2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3625
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3626
                __digit1 = ((unsigned *)__src)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3627
                __digit2 = ((unsigned *)__src)[1];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3628
                asm ("addl %%edx,%%ecx          \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3629
                      adcl $0, %%eax            \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3630
                      movl $0, %%edx            \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3631
                      adcl $0, %%edx"
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3632
                        : "=d"  (ASM_ULONGCAST(__carry)),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3633
                          "=c"  (ASM_ULONGCAST(__sum)),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3634
                          "=a"  (ASM_ULONGCAST(__sum2))
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3635
                        : "0"   (ASM_ULONGCAST(__carry)),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3636
                          "1"   (__digit1),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3637
                          "2"   (__digit2));
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3638
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3639
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3640
                ((unsigned int *)(__src + __ptrDelta))[1] = __sum2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3641
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3642
                __src += 8;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3643
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3644
                if (__carry == 0) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3645
                    while (__src <= __srcLastX) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3646
                        /* copy over words */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3647
                        ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3648
                        ((unsigned int *)(__src + __ptrDelta))[1] = ((unsigned int *)__src)[1];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3649
                        __src += 8;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3650
                    }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3651
                    while (__src <= __srcLast) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3652
                        /* copy over bytes */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3653
                        __src[__ptrDelta] = __src[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3654
                        __src ++;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3655
                    }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3656
                    goto doneSource;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3657
                }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3658
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3659
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3660
            __srcLastX = __srcLastX + 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3661
            if (__src <= __srcLastX) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3662
                unsigned int __sum, __digit;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3663
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3664
                __digit = ((unsigned *)__src)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3665
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3666
                asm ("addl %%eax,%%edx  \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3667
                      movl $0,%%eax     \n\
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3668
                      adcl $0,%%eax"
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3669
                        : "=a"  (ASM_ULONGCAST(__carry)),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3670
                          "=d"  (ASM_ULONGCAST(__sum))
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3671
                        : "0"   (ASM_ULONGCAST(__carry)),
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3672
                          "1"   (__digit) );
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3673
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3674
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3675
                __src += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3676
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3677
                if (__carry == 0) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3678
                    while (__src <= __srcLast) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3679
                        /* copy over bytes */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3680
                        __src[__ptrDelta] = __src[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3681
                        __src ++;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3682
                    }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3683
                    goto doneSource;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3684
                }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3685
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3686
        }
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3687
#  endif
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3688
# else /* not i386-GNUC */
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3689
#  if defined(__win32__) && defined(__BORLANDC__) && defined(__x86__) && (__POINTER_SIZE__ == 4)
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3690
        {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3691
            unsigned char *__srcLast4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3692
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3693
            /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3694
             * add long-wise
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3695
             */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3696
            __srcLast4 = __srcLast - 3;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3697
            while (__src <= __srcLast4) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3698
                unsigned int __sum;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3699
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3700
                __sum = ((unsigned int *)__src)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3701
                asm {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3702
                      mov eax, __sum
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3703
                      add eax, __carry
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3704
                      mov edx, 0
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3705
                      adc edx, 0
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3706
                      mov __sum, eax
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3707
                      mov __carry, edx
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3708
                    }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3709
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3710
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3711
                __src += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3712
                if (__carry == 0) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3713
                    while (__src <= __srcLast4) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3714
                        /* copy over words */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3715
                        ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3716
                        __src += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3717
                    }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3718
                    while (__src <= __srcLast) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3719
                        /* copy over bytes */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3720
                        __src[__ptrDelta] = __src[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3721
                        __src ++;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3722
                    }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3723
                    goto doneSource;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3724
                }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3725
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3726
        }
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3727
#  else /* not i386-WIN32 */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3728
#   if defined(__LSBFIRST__) && (__POINTER_SIZE__ == 8)
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3729
        {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3730
            unsigned char *__srcLast4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3731
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3732
            /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3733
             * add long-wise
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3734
             */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3735
            __srcLast4 = __srcLast - 3;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3736
            while (__src <= __srcLast4) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3737
                unsigned INT __sum;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3738
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3739
                __sum = (INT)(((unsigned int *)__src)[0]);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3740
                __sum += __carry;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3741
                ((unsigned int *)(__src + __ptrDelta))[0] = __sum /* & 0xFFFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3742
                __src += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3743
                __carry = __sum >> 32;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3744
                if (__carry == 0) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3745
                    while (__src <= __srcLast4) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3746
                        /* copy over words */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3747
                        ((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3748
                        __src += 4;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3749
                    }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3750
                    while (__src <= __srcLast) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3751
                        /* copy over bytes */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3752
                        __src[__ptrDelta] = __src[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3753
                        __src ++;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3754
                    }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3755
                    goto doneSource;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3756
                }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3757
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3758
        }
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3759
#   endif /* LSB+64bit */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3760
#  endif /* __i386__ & WIN32 */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3761
# endif /* __i386__ & GNUC */
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  3762
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3763
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3764
         * add short-wise
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3765
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3766
        while (__src < __srcLast) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3767
            __carry += ((unsigned short *)__src)[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3768
            ((unsigned short *)(__src + __ptrDelta))[0] = __carry /* & 0xFFFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3769
            __carry >>= 16;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3770
            __src += 2;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3771
        }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3772
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3773
         * last (odd) byte
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3774
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3775
        if (__src <= __srcLast) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3776
            __carry += __src[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3777
            __src[__ptrDelta] = __carry /* & 0xFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3778
            __carry >>= 8;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3779
            __src++;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3780
        }
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3781
#else /* not __LSBFIRST__ */
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  3782
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3783
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3784
         * add byte-wise
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3785
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3786
        while (__src <= __srcLast) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3787
            __carry += __src[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3788
            __src[__ptrDelta] = __carry /* & 0xFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3789
            __src++;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3790
            __carry >>= 8;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3791
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3792
            if (__carry == 0) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3793
                while (__src <= __srcLast) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3794
                    /* copy over rest */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3795
                    __src[__ptrDelta] = __src[0];
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3796
                    __src++;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3797
                }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3798
                goto doneSource;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3799
            }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3800
        }
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3801
#endif /* __LSBFIRST__ */
4185
375439993eb7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4182
diff changeset
  3802
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  3803
    doneSource: ;
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3804
        /*
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3805
         * now, at most one other byte is to be stored ...
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3806
         */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3807
        if (__len < __rsltLen) {
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3808
            __src[__ptrDelta] = __carry /* & 0xFF */;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3809
            __src++;
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3810
        }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3811
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3812
        if (__src[__ptrDelta-1] != 0) {      /* lastDigit */
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3813
            RETURN (result);
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3814
        }
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3815
        // must compress
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3816
        ok = true;
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3817
    }
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3818
%}.
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3819
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3820
    ok ~~ true ifTrue:[
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3821
        index := 1.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3822
        carry := aSmallInteger abs.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3823
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3824
        [carry ~~ 0] whileTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3825
            (index <= len) ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3826
                carry := (digitByteArray basicAt:index) + carry.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3827
            ].
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3828
            resultDigitByteArray basicAt:index put:(lastDigit := carry bitAnd:16rFF).
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3829
            carry := carry bitShift:-8.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3830
            index := index + 1
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3831
        ].
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3832
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3833
        (index <= rsltLen) ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3834
            [index <= len] whileTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3835
                resultDigitByteArray basicAt:index put:(digitByteArray basicAt:index).
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3836
                index := index + 1
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3837
            ].
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3838
            lastDigit := 0.
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3839
        ].
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3840
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3841
        (lastDigit ~~ 0 and:[rsltLen > SmallInteger maxBytes]) ifTrue:[
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3842
            ^ result
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  3843
        ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3844
    ].
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3845
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3846
    ^ result compressed
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3847
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3848
    "Modified: 24.3.1997 / 21:32:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3849
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3850
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3851
absLess:aLargeInteger
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3852
    "return true, if abs(self) < abs(theArgument).
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3853
     This handles unnormalized largeIntegers."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3854
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3855
    |myLen "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3856
     otherLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3857
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3858
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3859
     otherDigitByteArray |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3860
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3861
%{  /* NOCONTEXT */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3862
#if defined(__LSBFIRST__)
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3863
    if (__isByteArray(__INST(digitByteArray))
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3864
     && __isLargeInteger(aLargeInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3865
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3866
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3867
	if (__isByteArray(_otherDigitByteArray)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3868
	    unsigned char *_myDigits = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3869
	    unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3870
	    INT _myLen = __byteArraySize(__INST(digitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3871
	    INT _otherLen = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3872
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3873
	    if (_myLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3874
		if (_otherLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3875
		    unsigned INT _myVal = *((unsigned INT *)_myDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3876
		    unsigned INT _otherVal = *((unsigned INT *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3877
		    RETURN( (_myVal < _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3878
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3879
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3880
# if defined(UINT64) && (__POINTER_SIZE__ != 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3881
	    if (_myLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3882
		if (_otherLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3883
		    UINT64 _myVal = (UINT64)(*((UINT *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3884
		    UINT64 _otherVal = *((UINT64 *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3885
		    RETURN( (_myVal < _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3886
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3887
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3888
		if (_myLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3889
		    if (_otherLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3890
			UINT64 _myVal = (*((UINT64 *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3891
			UINT64 _otherVal = *((UINT64 *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3892
			RETURN( (_myVal < _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3893
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3894
		    if (_otherLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3895
			UINT64 _myVal = (*((UINT64 *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3896
			UINT64 _otherVal = (UINT64) *((UINT *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3897
			RETURN( (_myVal < _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3898
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3899
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3900
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3901
# endif /* UINT64 */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3902
	    while ((_myLen > 0) && (_myDigits[_myLen-1] == 0)) _myLen--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3903
	    while ((_otherLen > 0) && (_otherDigits[_otherLen-1] == 0)) _otherLen--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3904
	    if (_myLen < _otherLen) { RETURN( true ); }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3905
	    if (_myLen > _otherLen) { RETURN (false ); }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3906
	    while (_myLen-- > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3907
		unsigned char _d1 = _myDigits[_myLen];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3908
		unsigned char _d2 = _otherDigits[_myLen];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3909
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3910
		if (_d1 != _d2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3911
		    if (_d1 < _d2) { RETURN( true ); }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3912
		    RETURN (false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3913
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3914
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3915
	    RETURN (false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3916
	}
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3917
    }
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3918
#endif /* LSBFIRST */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3919
%}.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3920
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3921
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3922
    otherDigitByteArray := aLargeInteger digitBytes.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3923
    otherLen := otherDigitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3924
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3925
    "/ the highest digit(s) should not be zero
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3926
    "/ when properly normalized;
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3927
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3928
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3929
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3930
    [myLen > 0 and:[(digitByteArray basicAt:myLen) == 0]] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3931
	myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3932
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3933
    [otherLen > 0 and:[(otherDigitByteArray basicAt:otherLen) == 0]] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3934
	otherLen := otherLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3935
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3936
    (myLen < otherLen) ifTrue:[^ true].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3937
    (myLen > otherLen) ifTrue:[^ false].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3938
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3939
    [myLen > 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3940
	d1 := digitByteArray basicAt:myLen.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3941
	d2 := otherDigitByteArray basicAt:myLen.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3942
	d1 == d2 ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3943
	    (d1 < d2) ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3944
	    ^ false
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3945
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3946
	myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3947
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3948
    ^ false
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3949
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3950
    "
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3951
     |a b|
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3952
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3953
     a := 16rFEFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3954
     b := 16rFFFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3955
     Time millisecondsToRun:[
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3956
       10000000 timesRepeat:[ a absLess_old:b ]
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3957
     ]    1185 1233 1185
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3958
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3959
     |a b|
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3960
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3961
     a := 16rFEFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3962
     b := 16rFFFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3963
     Time millisecondsToRun:[
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3964
       10000000 timesRepeat:[ a absLess_n:b ]
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  3965
     ] 686 655 702 702
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3966
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3967
     16rEFFFFFFF  absLess_n: 16rFFFFFFFF
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  3968
     16rEFFFFFFF  absLess: 16rFFFFFFFF
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3969
    "
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3970
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3971
    "Modified: / 3.5.1999 / 08:06:28 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3972
    "Modified: / 8.5.1999 / 18:37:11 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3973
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3974
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3975
absLessEq:aLargeInteger
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3976
    "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
  3977
     This handles unnormalized largeIntegers."
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3978
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3979
    |myLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3980
     otherLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3981
     d1   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3982
     d2   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3983
     otherDigitByteArray |
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3984
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3985
%{  /* NOCONTEXT */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3986
#if defined(__LSBFIRST__)
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3987
    if (__isByteArray(__INST(digitByteArray))
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3988
     && __isLargeInteger(aLargeInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3989
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3990
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3991
	if (__isByteArray(_otherDigitByteArray)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3992
	    unsigned char *_myDigits = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3993
	    unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3994
	    INT _myLen = __byteArraySize(__INST(digitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3995
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3996
	    if (_myLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3997
		INT _otherLen = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3998
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3999
		if (_otherLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4000
		    unsigned INT _myVal = *((unsigned INT *)_myDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4001
		    unsigned INT _otherVal = *((unsigned INT *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4002
		    RETURN( (_myVal <= _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4003
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4004
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4005
# if defined(UINT64) && (__POINTER_SIZE__ != 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4006
	    if (_myLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4007
		INT _otherLen = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4008
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4009
		if (_otherLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4010
		    UINT64 _myVal = (UINT64)(*((UINT *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4011
		    UINT64 _otherVal = *((UINT64 *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4012
		    RETURN( (_myVal <= _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4013
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4014
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4015
		if (_myLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4016
		    INT _otherLen = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4017
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4018
		    if (_otherLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4019
			UINT64 _myVal = (*((UINT64 *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4020
			UINT64 _otherVal = *((UINT64 *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4021
			RETURN( (_myVal <= _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4022
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4023
		    if (_otherLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4024
			UINT64 _myVal = (*((UINT64 *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4025
			UINT64 _otherVal = (UINT64) *((UINT *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4026
			RETURN( (_myVal <= _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4027
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4028
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4029
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4030
# endif /* UINT64 */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4031
	}
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4032
    }
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4033
#endif /* LSBFIRST */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4034
%}.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4035
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4036
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4037
    otherDigitByteArray := aLargeInteger digitBytes.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4038
    otherLen := otherDigitByteArray size.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4039
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4040
    "/ the highest digit(s) should not be zero
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4041
    "/ when properly normalized;
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4042
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4043
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4044
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4045
    [(digitByteArray basicAt:myLen) == 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4046
	myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4047
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4048
    [(otherDigitByteArray basicAt:otherLen) == 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4049
	otherLen := otherLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4050
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4051
    (myLen < otherLen) ifTrue:[^ true].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4052
    (myLen > otherLen) ifTrue:[^ false].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4053
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4054
    [myLen > 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4055
	d1 := digitByteArray basicAt:myLen.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4056
	d2 := otherDigitByteArray basicAt:myLen.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4057
	d1 == d2 ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4058
	    (d1 < d2) ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4059
	    ^ false.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4060
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4061
	myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4062
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4063
    ^ true
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4064
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4065
    "Created: / 13.2.1998 / 12:19:45 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4066
    "Modified: / 30.4.1999 / 12:46:31 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4067
    "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
  4068
!
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4069
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4070
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
  4071
    "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
  4072
     with sign: newSign.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4073
     The result is normalized. The argument must be a largeInteger
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4074
     with a byteSize smaller than the receiver's byteSize.
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4075
     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
  4076
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4077
    |result done
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4078
     otherDigitByteArray resultDigitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4079
     len1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4080
     len2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4081
     index  "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4082
     borrow "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4083
     diff   "{ Class: SmallInteger }"
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4084
     carry  "{ Class: SmallInteger }"
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4085
     lastDigit
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4086
     lResult ok|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4087
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4088
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4089
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4090
    len2 := otherDigitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4091
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  4092
    len1 > len2 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4093
	lResult := len1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  4094
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4095
	lResult := (len1 max: len2) + 1.
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  4096
    ].
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  4097
    result := self class basicNew numberOfDigits:lResult sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4098
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4099
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  4100
    lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  4101
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4102
%{
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4103
    OBJ _digitByteArray = __INST(digitByteArray);
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4104
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4105
    if (__isByteArray(_digitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4106
     && __isByteArray(otherDigitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4107
     && __isByteArray(resultDigitByteArray)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4108
	int __len1 = __intVal(len1);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4109
	int __len2 = __intVal(len2);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4110
	int __minLen = __len1 < __len2 ? __len1 : __len2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4111
	int __index, __borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4112
	INT __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4113
	unsigned char *__myDigits, *__otherDigits, *__resultDigits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4114
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4115
	ok = true;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4116
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4117
	__resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4118
	__otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4119
	__myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4120
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4121
	__index = 1;
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  4122
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4123
#if defined(__LSBFIRST__)
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4124
# if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4125
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4126
	 * subtract int-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4127
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4128
	while ((__index+3) <= __minLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4129
	    /* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4130
	    __diff = ((unsigned int *)(__myDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4131
	    __diff -= ((unsigned int *)(__otherDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4132
	    __diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4133
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4134
	    if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4135
		__borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4136
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4137
		__borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4138
		/* __diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4139
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4140
	    ((unsigned int *)(__resultDigits+__index-1))[0] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4141
	    __index += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4142
	}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4143
# endif /* 64bit */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4144
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4145
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4146
	 * subtract short-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4147
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4148
	while (__index < __minLen) {   /* i.e. index+1 <= minLen */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4149
	    /* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4150
	    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4151
	    __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4152
	    __diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4153
	    if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4154
		__borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4155
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4156
		__borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4157
		/* __diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4158
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4159
	    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4160
	    __index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4161
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4162
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4163
	if (__index == __minLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4164
	    /* one of the operands has odd length - cannot continue short-wise */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4165
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4166
	    if (__len1 > __len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4167
		while (__index < __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4168
		    /* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4169
		    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4170
		    __diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4171
		    if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4172
			__borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4173
			((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4174
			__index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4175
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4176
			/* copy over rest */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4177
			while (__index < __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4178
			    ((unsigned short *)(__resultDigits+__index-1))[0] = ((unsigned short *)(__myDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4179
			    __index+=2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4180
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4181
			if (__index <= __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4182
			    __resultDigits[__index-1] = __myDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4183
			    __index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4184
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4185
			break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4186
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4187
		    __borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4188
		    /* __diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4189
		    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4190
		    __index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4191
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4192
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4193
		if (__len2 > __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4194
		    while (__index < __len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4195
			/* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4196
			__diff = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4197
			__diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4198
			__diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4199
			if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4200
			    __borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4201
			} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4202
			    __borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4203
			    /* __diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4204
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4205
			((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4206
			__index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4207
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4208
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4209
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4210
	}
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  4211
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4212
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4213
	 * subtract byte-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4214
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4215
	while (__index <= __minLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4216
	    /* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4217
	    __diff = __myDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4218
	    __diff -= __otherDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4219
	    __diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4220
	    if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4221
		__borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4222
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4223
		__borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4224
		/* __diff += 0x100; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4225
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4226
	    __resultDigits[__index-1] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4227
	    __index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4228
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4229
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4230
	if (__len1 > __len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4231
	    while (__index <= __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4232
		/* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4233
		__diff = __myDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4234
		__diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4235
		if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4236
		    __borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4237
		    /* copy over rest */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4238
		    __resultDigits[__index-1] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4239
		    __index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4240
		    while (__index <= __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4241
			__resultDigits[__index-1] = __myDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4242
			__index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4243
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4244
		    break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4245
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4246
		__borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4247
		/* __diff += 0x100; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4248
		__resultDigits[__index-1] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4249
		__index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4250
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4251
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4252
	    if (__len2 > __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4253
		while (__index <= __len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4254
		    /* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4255
		    __diff = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4256
		    __diff -= __otherDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4257
		    __diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4258
		    if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4259
			__borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4260
		    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4261
			__borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4262
			/* __diff += 0x100; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4263
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4264
		    __resultDigits[__index-1] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4265
		    __index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4266
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4267
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4268
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4269
	borrow = __mkSmallInteger(__borrow);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4270
	index = __mkSmallInteger(__index);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4271
	lastDigit = __mkSmallInteger(__resultDigits[__intVal(lResult)-1]);
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4272
    }
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4273
%}.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4274
    ok == true ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4275
	index := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4276
	borrow := 0.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4277
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4278
	done := false.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4279
	[done] whileFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4280
	    diff := borrow.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4281
	    (index <= len1) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4282
		diff := diff + (digitByteArray basicAt:index).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4283
		(index <= len2) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4284
		    diff := diff - (otherDigitByteArray basicAt:index)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4285
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4286
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4287
		(index <= len2) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4288
		    diff := diff - (otherDigitByteArray basicAt:index)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4289
		] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4290
		    "end reached"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4291
		    done := true
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4292
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4293
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4294
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4295
	    "/ workaround for
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4296
	    "/ gcc code generator bug
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4297
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4298
	    (diff >= 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4299
		borrow := 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4300
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4301
		borrow := -1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4302
		diff := diff + 16r100
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4303
	    ].
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4304
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4305
    "/        (diff < 0) ifTrue:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4306
    "/            borrow := -1.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4307
    "/            diff := diff + 16r100
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4308
    "/        ] ifFalse:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4309
    "/            borrow := 0
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4310
    "/        ].
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4311
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4312
	    resultDigitByteArray basicAt:index put:diff.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4313
	    index := index + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4314
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4315
	lastDigit := resultDigitByteArray basicAt:lResult.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4316
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  4317
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4318
    (borrow ~~ 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4319
	"/ must generate 255's complement
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4320
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4321
	result sign:newSign negated.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4322
	[index <= lResult] whileTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4323
	    resultDigitByteArray basicAt:index put:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4324
	    index := index + 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4325
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4326
	index := lResult.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4327
	[index > 0] whileTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4328
	    resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4329
	    index := index - 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4330
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4331
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4332
	index := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4333
	carry := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4334
	[carry ~~ 0] whileTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4335
	    (index <= lResult) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4336
		carry := (resultDigitByteArray basicAt:index) + carry.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4337
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4338
	    resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4339
	    carry := carry bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4340
	    index := index + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4341
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4342
	lastDigit := resultDigitByteArray basicAt:lResult.
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  4343
    ].
15242
4539185c87ed class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15240
diff changeset
  4344
    (lastDigit == 0 or:[lResult <= SmallInteger maxBytes]) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4345
	^ result compressed.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4346
    ].
15242
4539185c87ed class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15240
diff changeset
  4347
    ^ result
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  4348
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  4349
    "Modified: 5.11.1996 / 14:09:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4350
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4351
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4352
absMod:anInteger
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4353
    "return a LargeIntegers representing
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4354
     abs(self) \\ abs(theArgument).
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4355
     Used as a helper for \\ and rem:"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4356
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4357
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4358
    |dividend divisor
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4359
     shift "{ Class: SmallInteger }" |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4360
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4361
    anInteger == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4362
	^ ZeroDivide raiseRequestWith:thisContext
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4363
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4364
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4365
    self = anInteger ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4366
	^ 0
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4367
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4368
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4369
    shift := self highBit - anInteger highBit.
16124
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  4370
    dividend := self class digitBytes:digitByteArray copy. "/ self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4371
    shift < 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4372
	^ dividend compressed.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4373
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  4374
    shift == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4375
	divisor := LargeInteger digitBytes:(anInteger digitBytes copy). "/ anInteger simpleDeepCopy
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  4376
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4377
	divisor := anInteger bitShift:shift.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4378
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4379
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4380
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4381
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4382
    [shift > 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4383
	(dividend absLess:divisor) ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4384
	    (dividend absDestructiveSubtract: divisor) ifFalse:[ "result == 0"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4385
		^ 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4386
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4387
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4388
	shift := shift - 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4389
	divisor div2.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4390
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4391
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4392
    ^ dividend compressed
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4393
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4394
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4395
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absMod:4000000001] ]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4396
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absDivMod:4000000001] ]
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4397
     16000000000 absMod:4000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4398
     16000000000 absMod:3000000000
19126
98adb7dc1950 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19102
diff changeset
  4399
     16000000000000000000 absMod:16000000000000000000
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4400
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4401
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4402
    "Modified: / 5.11.1996 / 18:40:24 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4403
    "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
  4404
    "Modified: / 26.7.1999 / 10:46:18 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4405
!
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4406
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4407
absMul:aLargeInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4408
    "return a LargeInteger representing abs(self) * abs(theArgument)"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4409
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4410
    |result otherDigitByteArray resultDigitByteArray ok
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4411
     idx      "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4412
     carry    "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4413
     len1     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4414
     len2     "{ Class: SmallInteger }"
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4415
     lenRslt  "{ Class: SmallInteger }"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4416
     dstIndex "{ Class: SmallInteger }"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  4417
     prod     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  4418
     v        "{ Class: SmallInteger }"|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4419
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4420
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4421
    otherDigitByteArray := aLargeInteger digitBytes.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4422
    len2 := otherDigitByteArray size.
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4423
    lenRslt := len1 + len2.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4424
    UseKarazuba ~~ false ifTrue:[
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4425
        lenRslt > 400 ifTrue:[ ^ self absMulKarazuba:aLargeInteger ].
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4426
    ].
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4427
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4428
    result := self class basicNew numberOfDigits:lenRslt.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4429
    resultDigitByteArray := result digitBytes.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4430
    ok := false.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4431
%{
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  4432
    if (__isByteArray(__INST(digitByteArray))
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4433
     && __isByteArray(otherDigitByteArray)
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4434
     && __isByteArray(resultDigitByteArray)) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4435
        unsigned char *myBytes = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4436
        unsigned char *otherBytes = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4437
        unsigned char *resultBytes = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4438
        unsigned char *_p1, *_pResult0, *_p1Last, *_p2Last;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4439
        unsigned INT _v;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4440
        int _len1 = __intVal(len1);
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4441
        int _len2 = __intVal(len2);
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4442
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4443
        _p1Last = myBytes    + _len1 - 1;  /* the last byte */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4444
        _p2Last = otherBytes + _len2 - 1;  /* the last byte */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4445
        _pResult0 = resultBytes;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4446
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4447
        /*
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4448
         *         aaa...aaa      f1[0] * f2
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4449
         * +      bbb...bbb       f1[1] * f2
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4450
         * +     ccc...ccc        f1[2] * f2
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4451
         * +    ...
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4452
         * +   xxx...xxx          f1[high] * f2
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4453
         *
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4454
         * start short-wise
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4455
         * bounds: (16rFFFF * 16rFFFF) + 16rFFFF -> FFFF0000
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4456
         */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4457
        _p1 = myBytes;
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  4458
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4459
#if defined(__LSBFIRST__) && (__POINTER_SIZE__ == 8)
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4460
        /* loop over ints of f1 */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4461
        for (; _p1 <= (_p1Last-3); _p1 += 4, _pResult0 += 4) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4462
            unsigned char *_pResult = _pResult0;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4463
            unsigned char *_p2;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4464
            unsigned INT word1 = ((unsigned int *)_p1)[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4465
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4466
            _v = 0;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4467
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4468
            /* loop over ints of f2 */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4469
            for (_p2 = otherBytes; _p2 <= (_p2Last-3); _p2 += 4) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4470
                _v = word1 * (unsigned INT)(((unsigned int *)_p2)[0])
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4471
                     + _v + (unsigned INT)((unsigned int *)_pResult)[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4472
                ((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4473
                _v >>= 32; /* now _v contains the carry*/
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4474
                _pResult += 4;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4475
            }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4476
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4477
            /* possible odd up to 3 highBytes of f2 */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4478
            for ( ; _p2 <= _p2Last; _p2++) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4479
                _v = word1 * (unsigned INT)(_p2[0])
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4480
                     + _v + (unsigned INT)(_pResult[0]);
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4481
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4482
                ((unsigned char *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4483
                _v >>= 8; /* now _v contains the carry*/
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4484
                _pResult++;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4485
            }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4486
            /* distribute leftover carry byte-wise */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4487
            for ( ; _v; _v >>= 8, _pResult++) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4488
                _v += _pResult[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4489
                _pResult[0] = _v /* & 0xFF */;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4490
            }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4491
        }
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4492
#endif /* 64bit */
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4493
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4494
        /* possible odd high short of f1 (or shortLoop, if not 64bit) */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4495
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4496
        for (; _p1 < _p1Last; _p1 += 2, _pResult0 += 2) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4497
            unsigned char *_pResult = _pResult0;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4498
            unsigned char *_p2 = otherBytes;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4499
            unsigned int short1 = ((unsigned short *)_p1)[0];
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  4500
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4501
#if !defined(__LSBFIRST__)
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4502
            short1 = ((short1 >> 8) & 0xFF) | ((short1 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  4503
#endif
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4504
            _v = 0;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4505
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4506
            /* loop over shorts of f2 */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4507
            for ( ; _p2 < _p2Last; _p2 += 2, _pResult += 2) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4508
#if !defined(__LSBFIRST__)
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4509
                unsigned int _short2  = ((unsigned short *)_p2)[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4510
                unsigned int _short3  = ((unsigned short *)_pResult)[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4511
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4512
                _short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4513
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4514
                _v = (short1 * _short2) + _short3 + _v;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4515
                _pResult[0] = _v;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4516
                _pResult[1] = _v >> 8;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4517
#else /* __LSBFIRST__ */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4518
                _v = (short1 * ((unsigned short *)_p2)[0]) + _v + ((unsigned short *)_pResult)[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4519
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4520
#endif /* __LSBFIRST__ */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4521
                _v >>= 16; /* now _v contains the carry*/
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4522
            }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4523
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4524
            /* possible odd highByte of f2 */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4525
            for ( ; _p2 <= _p2Last; _p2++, _pResult += 2) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4526
#if !defined(__LSBFIRST__)
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4527
                unsigned int _short3 = ((unsigned short *)_pResult)[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4528
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4529
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4530
                _v = (short1 * _p2[0]) + _v + _short3;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4531
                _pResult[0] = _v;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4532
                _pResult[1] = _v >> 8;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4533
#else /* __LSBFIRST__ */
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4534
                _v = (short1 * _p2[0]) + _v + ((unsigned short *)_pResult)[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4535
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4536
#endif /* __LSBFIRST__ */
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4537
                _v >>= 16; /* now _v contains the carry*/
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4538
            }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4539
            /* distribute leftover carry byte-wise */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4540
            for ( ; _v; _v >>= 8, _pResult++) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4541
                _v += _pResult[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4542
                _pResult[0] = _v /* & 0xFF */;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4543
            }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4544
        }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4545
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4546
        /* possible odd highByte of f1 (or byteLoop, if above is ever disabled) */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4547
        for (; _p1 <= _p1Last; _p1++, _pResult0++) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4548
            unsigned char *_pResult = _pResult0;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4549
            unsigned char *_p2 = otherBytes;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4550
            unsigned int byte1 = _p1[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4551
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4552
            _v = 0;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4553
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4554
            /* loop over shorts of f2 */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4555
            for ( ; _p2 < _p2Last; _p2 += 2, _pResult += 2) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4556
#if !defined(__LSBFIRST__)
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4557
                unsigned int _short2 = ((unsigned short *)_p2)[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4558
                unsigned int _short3  = ((unsigned short *)_pResult)[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4559
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4560
                _short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4561
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4562
                _v = (byte1 * _short2) + _v +_short3;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4563
                _pResult[0] = _v;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4564
                _pResult[1] = _v >> 8;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4565
#else /* __LSBFIRST__ */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4566
                _v = (byte1 * ((unsigned short *)_p2)[0]) + _v + ((unsigned short *)_pResult)[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4567
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4568
#endif /* __LSBFIRST__ */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4569
                _v >>= 16; /* now _v contains the carry*/
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4570
            }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4571
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4572
            /* possible odd highByte of f2 (or byteLoop, if not __LSBFIRST__) */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4573
            for ( ; _p2 <= _p2Last; _p2++, _pResult++) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4574
                _v = (byte1 * _p2[0]) + _v + _pResult[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4575
                _pResult[0] = _v /* & 0xFF */;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4576
                _v >>= 8; /* now _v contains the carry*/
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4577
            }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4578
            /* distribute leftover carry byte-wise */
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4579
            for ( ; _v; _v >>= 8, _pResult++) {
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4580
                _v += _pResult[0];
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4581
                _pResult[0] = _v /* & 0xFF */;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4582
            }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4583
        }
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4584
        ok = true;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4585
    }
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4586
%}.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4587
    ok ifFalse:[
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4588
        1 to:len1 do:[:index1 |
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4589
            1 to:len2 do:[:index2 |
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4590
                dstIndex := index1 + index2 - 1.
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4591
                prod := (digitByteArray basicAt:index1) * (otherDigitByteArray basicAt:index2).
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4592
                prod := prod + (resultDigitByteArray basicAt:dstIndex).
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4593
                resultDigitByteArray basicAt:dstIndex put:(prod bitAnd:16rFF).
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4594
                carry := prod bitShift:-8.
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4595
                carry ~~ 0 ifTrue:[
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4596
                    idx := dstIndex + 1.
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4597
                    [carry ~~ 0] whileTrue:[
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4598
                        v := (resultDigitByteArray basicAt:idx) + carry.
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4599
                        resultDigitByteArray basicAt:idx put:(v bitAnd:255).
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4600
                        carry := v bitShift:-8.
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4601
                        idx := idx + 1
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4602
                    ]
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4603
                ]
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4604
            ]
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4605
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4606
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  4607
    ^ result compressed
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4608
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4609
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4610
absMulKarazuba:aLargeInteger
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4611
    "return a LargeInteger representing abs(self) * abs(theArgument) using the karazuba algorithm.
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4612
        a = (2^n * p) + q
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4613
        b = (2^n * r) + s
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4614
        a * b   = ((2^n * p) + q) * ((2^n * r) + s)
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4615
                = 2^(n+n)*p*r + 2^n*p*s + 2^n*q*r + q*s
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4616
                = 2^(n+n)*p*r + (p*r + q*s - (q-p)*(s-r))*2^n + q*s
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4617
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4618
        this is faster for sufficient large n1,n2
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4619
        because regular multiplication is O(n1*n2) and karazuma multiplies much smaller numbers
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4620
        (half number of bits) but does more multiplications (on smaller numbers) and req's more
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4621
        additions and subtractions (on smaller numbers).
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4622
        The break-even for when to use regular multiplication has been determined heuristically
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4623
        and is somewhere around 1600 bits (digitLength of 200).
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4624
        (see test in absMul:)
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4625
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4626
        To disable karazuba, set UseKarazuba to false.
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4627
    "
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4628
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4629
    "/ compute half-sized pi and qi...
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4630
    |l1 l2 n nh p q r s pr qs q_p s_r q_ps_r pr_raisedTo_n mdl_raisedTo_nh|
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4631
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4632
    l1 := self digitLength.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4633
    l2 := aLargeInteger digitLength.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4634
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4635
    n := l1 max:l2.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4636
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4637
    nh := (n / 2) ceiling. n := nh * 2.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4638
    p := LargeInteger digitBytes:(digitByteArray copyFrom:nh+1) sign:1. "/ high bits of nr1
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4639
    q := LargeInteger digitBytes:(digitByteArray copyToMax:nh) sign:1.   "/ low bits of nr1
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4640
    r := LargeInteger digitBytes:(aLargeInteger digitBytes copyFrom:nh+1) sign:1. "/ high bits of nr2
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4641
    s := LargeInteger digitBytes:(aLargeInteger digitBytes copyToMax:nh).           "/ low bits of nr2
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4642
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4643
    p := p compressed.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4644
    q := q compressed.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4645
    r := r compressed.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4646
    s := s compressed.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4647
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4648
    pr := p * r.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4649
    qs := q * s.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4650
    q_p := q - p.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4651
    s_r := s - r.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4652
    q_ps_r := q_p * s_r.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4653
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4654
    pr_raisedTo_n := (pr bitShift:(n*8)).
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4655
    mdl_raisedTo_nh := ((pr + qs - q_ps_r) bitShift:(nh*8)).
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4656
    ^ pr_raisedTo_n + mdl_raisedTo_nh + qs
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4657
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4658
    "
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4659
     #(100 500 1000 2500 5000 10000 25000 50000 100000 250000 500000 1000000) do:[:exp |
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4660
         |nr r1 r2|
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4661
         nr := (3 raisedTo:exp) asInteger.
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4662
         Transcript show:exp; show:' nbytes: '; showCR:nr digitLength;
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4663
            show:'  normal: '; show:(Time microsecondsToRun:[ UseKarazuba := false. r1 := nr * nr ]); showCR:'us';
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4664
            show:'  karazuba: '; show:(Time microsecondsToRun:[ UseKarazuba := true. r2 := nr absMulKarazuba: nr]); showCR:'us'.
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4665
         self assert:(r1 = r2).
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4666
     ]
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4667
    "
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4668
!
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4669
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4670
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
  4671
    "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
  4672
     with sign: newSign.
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4673
     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
  4674
     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
  4675
     This is a helper for addition and subtraction - not for public use."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4676
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4677
    |result done otherDigitByteArray resultDigitByteArray
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4678
     len1   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4679
     len2   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4680
     newLen "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4681
     index  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4682
     carry  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4683
     sum    "{ Class: SmallInteger }" |
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4684
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4685
    otherDigitByteArray := aLargeInteger digitBytes.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4686
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4687
%{
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4688
    OBJ _digitByteArray = __INST(digitByteArray);
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4689
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4690
    if (__isByteArray(_digitByteArray)
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4691
     && __isByteArray(otherDigitByteArray)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4692
	int _len1, _len2, _newLen;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4693
	unsigned char *_myDigits, *_otherDigits, *_newDigits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4694
	int _index, _carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4695
	int _comLen;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4696
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4697
	_len1 = __byteArraySize(_digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4698
	_len2 = __byteArraySize(otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4699
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4700
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4701
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4702
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4703
	if (_len1 < _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4704
	    _comLen = _len1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4705
	    _newLen = _len2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4706
	    if (_otherDigits[_len2 - 1] == 0xFF) _newLen++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4707
	} else if (_len2 < _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4708
	    _comLen = _len2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4709
	    _newLen = _len1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4710
	    if (_myDigits[_len1 - 1] == 0xFF) _newLen++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4711
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4712
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4713
	     * there can only be an overflow from the high bytes,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4714
	     * if their sum is >= 255
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4715
	     * (with sum==255, a carry could still occur from the next lower bytes)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4716
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4717
	    _newLen = _len1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4718
	    if ((_otherDigits[_len2 - 1] + _myDigits[_len1 - 1]) >= 0xFF) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4719
		_newLen++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4720
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4721
		if (_newLen == sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4722
		    OBJ _uint;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4723
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4724
		    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4725
		     * two word-sized numbers, no carry - a very common case ...
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4726
		     */
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  4727
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4728
		    unsigned INT _sum = *(unsigned INT *)_otherDigits + *(unsigned INT *)_myDigits;
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  4729
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4730
		    unsigned INT _sum = __unsignedLongIntVal(self) + __unsignedLongIntVal(aLargeInteger);
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  4731
#endif /* not LSB_FIRST */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4732
		    if (_sum <= _MAX_INT) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4733
			_uint = __mkSmallInteger(_sum * __intVal(newSign));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4734
		    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4735
			_uint = __MKULARGEINT(_sum);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4736
			__LargeIntegerInstPtr(_uint)->l_sign = newSign;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4737
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4738
		    RETURN (_uint);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4739
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4740
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4741
	    _comLen = _len1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4742
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4743
	resultDigitByteArray = __BYTEARRAY_UNINITIALIZED_NEW_INT(_newLen);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4744
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4745
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4746
	 * must refetch - GC could have been invoked
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4747
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4748
	_digitByteArray = __INST(digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4749
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4750
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4751
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4752
	_newDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4753
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4754
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4755
	 * add them ...
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4756
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4757
	_index = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4758
	_carry = 0;
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  4759
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4760
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4761
# if (__POINTER_SIZE__ == 8) && defined(__GNUC__) && defined(__alpha__)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4762
#  if 0  /* not faster (on alpha) */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4763
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4764
	    int _comLen7;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4765
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4766
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4767
	     * have a 64bit integers;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4768
	     * add quad-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4769
	     * accessing bytes at: [index-1][index][index+1]..[index+6]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4770
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4771
	    _comLen7 = _comLen - 3 - 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4772
	    while (_index <= _comLen7) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4773
		UINT64 _sum, _t1, _t2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4774
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4775
		asm ("addq   %5,%6,%1         /* sum */                  \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4776
		      addq   %0,%1,%1         /* plus carryIn */         \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4777
		      cmpult %1,%5,%2         /* was there a carry ? */  \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4778
		      cmpult %1,%6,%3         /* was there a carry ? */  \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4779
		      bis    %2,%3,%0         /* carryOut */             \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4780
		     "
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4781
			: "=r"  (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4782
			  "=r"  (_sum),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4783
			  "r"   (_t1),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4784
			  "r"   (_t2)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4785
			: "r"   (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4786
			  "r"   (((unsigned long *)(&(_myDigits[_index - 1])))[0]),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4787
			  "r"   (((unsigned long *)(&(_otherDigits[_index - 1])))[0])
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4788
		    );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4789
		/* _sum = _sum & 0xFFFFFFFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4790
		((unsigned long *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4791
		_index += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4792
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4793
	}
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  4794
#  endif / notdef */
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  4795
# endif /* 64bit alpha */
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4796
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4797
# if (__POINTER_SIZE__ == 8)
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  4798
# if 0  /* not faster */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4799
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4800
	    int _comLen7;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4801
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4802
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4803
	     * have a 64bit integers;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4804
	     * add quad-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4805
	     * accessing bytes at: [index-1][index][index+1]..[index+6]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4806
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4807
	    _comLen7 = _comLen - 3 - 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4808
	    while (_index <= _comLen7) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4809
		UINT64 _sum, _t1, _t2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4810
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4811
		_t1 = ((UINT64 *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4812
		_t2 = ((UINT64 *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4813
		_sum = _t1 + _t2 + _carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4814
		((UINT64 *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4815
		_carry = (_sum < _t1) | (_sum < _t2);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4816
		_index += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4817
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4818
	}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4819
#  endif
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4820
# endif /* 64bit */
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  4821
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  4822
# ifdef UINT64
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4823
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4824
	    int _comLen3;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4825
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4826
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4827
	     * have a 64bit integer type;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4828
	     * add int-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4829
	     * accessing bytes at: [index-1][index][index+1][index+2]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4830
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4831
	    _comLen3 = _comLen - 3;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4832
	    while (_index <= _comLen3) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4833
		UINT64 _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4834
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4835
		/* do not merge the 3 lines below into one -
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4836
		 * (will do sign extension then, which is wrong here)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4837
		 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4838
		_sum = (unsigned)_carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4839
		_sum += ((unsigned int *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4840
		_sum += ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4841
		_carry = _sum >> 32;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4842
		/* _sum = _sum & 0xFFFFFFFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4843
		((unsigned int *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4844
		_index += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4845
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4846
	}
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  4847
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  4848
#  if defined(__i386__) && defined(__GNUC__) && (__POINTER_SIZE__ == 4)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4849
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4850
	    int _comLen3;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4851
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4852
	    _comLen3 = _comLen - 3 - 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4853
	    while (_index <= _comLen3) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4854
		unsigned int _sum, _sum2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4855
		unsigned int __in1A, __in1B, __in2A, __in2B;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4856
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4857
		__in1A = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4858
		__in2A = ((unsigned int *)(&(_myDigits[_index - 1])))[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4859
		__in1B = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4860
		__in2B = ((unsigned int *)(&(_otherDigits[_index - 1])))[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4861
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4862
		asm ("addl %%edx,%%eax  \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4863
		      movl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4864
		      adcl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4865
		      addl %5,%%eax     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4866
		      adcl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4867
					\n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4868
		      addl %%edx,%%ecx  \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4869
		      movl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4870
		      adcl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4871
		      addl %7,%%ecx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4872
		      adcl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4873
		     "
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4874
			: "=d"  (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4875
			  "=a"  (_sum),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4876
			  "=c"  (_sum2)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4877
			: "0"   (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4878
			  "1"   (__in1A),
19663
5e190fbb6f75 Relax inline assembly constraints in order to compile with -fno-omit-frame-pointer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 19662
diff changeset
  4879
			  "m"   (__in1B),
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4880
			  "2"   (__in2A),
19663
5e190fbb6f75 Relax inline assembly constraints in order to compile with -fno-omit-frame-pointer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 19662
diff changeset
  4881
			  "m"   (__in2B)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4882
		    );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4883
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4884
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4885
		((unsigned *)(&(_newDigits[_index - 1])))[1] = _sum2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4886
		_index += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4887
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4888
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4889
	     * add int-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4890
	     * accessing bytes at: [index-1][index][index+1][index+2]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4891
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4892
	    _comLen3 = _comLen3 + 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4893
	    if (_index <= _comLen3) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4894
		unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4895
		unsigned int __inA, __inB;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4896
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4897
		__inA = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4898
		__inB = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4899
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4900
		asm ("addl %%edx,%%eax      \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4901
		      movl $0,%%edx         \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4902
		      adcl $0,%%edx         \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4903
		      addl %4,%%eax         \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4904
		      adcl $0,%%edx"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4905
			: "=d"  (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4906
			  "=a"  (_sum)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4907
			: "0"   (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4908
			  "1"   (__inA),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4909
			  "rm"  (__inB)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4910
		    );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4911
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4912
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4913
		_index += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4914
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4915
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4916
#  endif /* __i386__ && GNUC */
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  4917
#  if defined(__win32__) && defined(__BORLANDC__) && defined(__x86__) && (__POINTER_SIZE__ == 4)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4918
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4919
	    int _comLen3;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4920
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4921
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4922
	     * add long-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4923
	     * accessing bytes at: [index-1][index][index+1][index+2]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4924
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4925
	    _comLen3 = _comLen - 3;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4926
	    while (_index <= _comLen3) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4927
		unsigned int _sum, _v1, _v2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4928
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4929
		_v1 = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4930
		_v2 = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4931
		asm {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4932
		      mov eax, _v1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4933
		      add eax, _v2
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4934
		      mov edx, 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4935
		      adc edx, 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4936
		      add eax, _carry
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4937
		      adc edx, 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4938
		      mov _carry, edx
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4939
		      mov _sum, eax
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4940
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4941
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4942
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4943
		_index += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4944
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4945
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4946
#  endif /* __i386__ && WIN32 */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4947
# endif /* INT64 */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4948
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4949
	 * add short-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4950
	 * accessing bytes at: [index-1][index]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4951
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4952
	while (_index < _comLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4953
	    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4954
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4955
	    _sum = _carry
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4956
		   + ((unsigned short *)(&(_myDigits[_index - 1])))[0]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4957
		   + ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4958
	    _carry = _sum >> 16;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4959
	    /* _sum = _sum & 0xFFFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4960
	    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4961
	    _index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4962
	}
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  4963
#else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4964
# ifdef __sparc__
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4965
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4966
	 * add short-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4967
	 * accessing bytes at: [index-1][index]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4968
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4969
	while (_index < _comLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4970
	    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4971
	    unsigned short _v1, _v2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4972
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4973
	    _v1 = ((unsigned short *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4974
	    _v2 = ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4975
	    _sum = _carry + (_v1>>8) + (_v2>>8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4976
	    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4977
	    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4978
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4979
	    _sum = _carry + (_v1 & 0xFF) + (_v2 & 0xFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4980
	    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4981
	    _newDigits[_index] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4982
	    _index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4983
	}
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  4984
# endif
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4985
#endif /* __LSBFIRST__ */
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  4986
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4987
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4988
	 * add byte-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4989
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4990
	while (_index <= _comLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4991
	    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4992
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4993
	    _sum = _carry
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4994
		   + _myDigits[_index - 1]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4995
		   + _otherDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4996
	    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4997
	    /* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4998
	    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4999
	    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5000
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5001
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5002
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5003
	 * rest
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5004
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5005
	if (_len1 > _len2) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  5006
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5007
	    if (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5008
		if ((_index - 1) & 1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5009
		    /* odd byte */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5010
		    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5011
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5012
		    _sum = _carry + _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5013
		    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5014
		    /* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5015
		    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5016
		    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5017
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5018
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5019
		while (_index < _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5020
		    /* shorts */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5021
		    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5022
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5023
		    _sum = _carry + *(unsigned short *)(&(_myDigits[_index - 1]));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5024
		    _carry = _sum >> 16;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5025
		    /* _sum = _sum & 0xFFFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5026
		    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5027
		    _index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5028
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5029
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5030
		if (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5031
		    /* last byte */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5032
		    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5033
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5034
		    _sum = _carry + _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5035
		    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5036
		    /* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5037
		    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5038
		    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5039
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5040
	    }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  5041
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5042
	    while (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5043
		unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5044
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5045
		_sum = _carry + _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5046
		_carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5047
		/* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5048
		_newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5049
		_index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5050
	    }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  5051
#endif /* not LSB */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5052
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5053
	    if (_len2 > _len1) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  5054
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5055
		if (_index <= _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5056
		    if ((_index - 1) & 1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5057
			/* odd byte */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5058
			unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5059
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5060
			_sum = _carry + _otherDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5061
			_carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5062
			/* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5063
			_newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5064
			_index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5065
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5066
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5067
		    while (_index < _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5068
			/* shorts */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5069
			unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5070
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5071
			_sum = _carry + *(unsigned short *)(&(_otherDigits[_index - 1]));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5072
			_carry = _sum >> 16;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5073
			/* _sum = _sum & 0xFFFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5074
			*(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5075
			_index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5076
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5077
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5078
		    if (_index <= _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5079
			/* last byte */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5080
			unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5081
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5082
			_sum = _carry + _otherDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5083
			_carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5084
			/* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5085
			_newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5086
			_index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5087
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5088
		}
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  5089
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5090
		while (_index <= _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5091
		    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5092
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5093
		    _sum = _carry + _otherDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5094
		    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5095
		    /* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5096
		    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5097
		    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5098
		}
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  5099
#endif /* not LSB */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5100
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5101
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5102
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5103
	while (_index <= _newLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5104
	    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5105
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5106
	    _sum = _carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5107
	    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5108
	    /* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5109
	    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5110
	    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5111
	}
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5112
    }
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5113
%}.
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5114
    resultDigitByteArray notNil ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5115
	result := self class basicNew.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5116
	result setDigits:resultDigitByteArray.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5117
	result setSign:newSign.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5118
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5119
	len1 := digitByteArray size.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5120
	len2 := otherDigitByteArray size.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5121
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5122
	"/ earlier versions estimated the newLength as:
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5123
	"/ (len1 max:len2) + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5124
	"/ and reduced the result.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5125
	"/ however, if one of the addends is smaller,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5126
	"/ the result will never require another digit,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5127
	"/ if the highest digit of the larger addent is
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5128
	"/ not equal to 255. Therefore, in most cases,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5129
	"/ we can avoid the computation and resizing
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5130
	"/ in #reduced.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5131
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5132
	len1 < len2 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5133
	    newLen := len2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5134
	    (otherDigitByteArray at:len2) == 16rFF ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5135
		newLen := newLen + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5136
	    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5137
	] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5138
	    len2 < len1 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5139
		newLen := len1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5140
		(digitByteArray at:len1) == 16rFF ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5141
		    newLen := newLen + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5142
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5143
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5144
		newLen := len1 + 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5145
	    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5146
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5147
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5148
	result := self class basicNew numberOfDigits:newLen.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5149
	result sign:newSign.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5150
	resultDigitByteArray := result digitBytes.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5151
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5152
	index := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5153
	carry := 0.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5154
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5155
	done := false.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5156
	[done] whileFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5157
	    sum := carry.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5158
	    (index <= len1) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5159
		sum := sum + (digitByteArray basicAt:index).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5160
		(index <= len2) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5161
		    sum := sum + (otherDigitByteArray basicAt:index)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5162
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5163
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5164
		(index <= len2) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5165
		    sum := sum + (otherDigitByteArray basicAt:index)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5166
		] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5167
		    "end reached"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5168
		    done := true
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5169
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5170
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5171
	    (sum >= 16r100) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5172
		carry := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5173
		sum := sum - 16r100
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5174
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5175
		carry := 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5176
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5177
	    resultDigitByteArray basicAt:index put:sum.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5178
	    index := index + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5179
	].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5180
    ].
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5181
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  5182
    ^ result compressed
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  5183
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5184
    "Modified: 11.8.1997 / 03:23:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5185
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5186
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5187
div2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5188
    "private helper for division:
15326
7cc303092044 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15312
diff changeset
  5189
       destructively divide the receiver by 2.
7cc303092044 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15312
diff changeset
  5190
       may leave the receiver unnormalized (i.e. with a leftover 0 high-byte)"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5191
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5192
    |prevBit|
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5193
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5194
%{  /* NOCONTEXT */
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5195
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5196
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5197
    if (__isByteArray(__digits)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5198
	int __nBytes = __byteArraySize(__digits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5199
	unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5200
	unsigned INT __this, __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5201
	int __idx;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5202
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5203
	if (__nBytes == 1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5204
	    __bp[0] >>= 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5205
	    RETURN (self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5206
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5207
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5208
	__idx = 1;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  5209
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  5210
#if defined(__LSBFIRST__)
15326
7cc303092044 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15312
diff changeset
  5211
# if (__POINTER_SIZE__ == 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5212
	if (sizeof(unsigned INT) == 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5213
	    int __endIndex = __nBytes - 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5214
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5215
	    if (__idx < __endIndex) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5216
		__this = ((unsigned INT *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5217
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5218
		while (__idx < __endIndex) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5219
		    __next = ((unsigned INT *)__bp)[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5220
		    __this = (__this >> 1) /* & 0x7FFFFFFFFFFFFFF */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5221
		    __this |= __next << 63;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5222
		    ((unsigned INT *)__bp)[0] = __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5223
		    __this = __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5224
		    __bp += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5225
		    __idx += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5226
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5227
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5228
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5229
	    if (__idx < (__nBytes - 4)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5230
		__this = ((unsigned int *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5231
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5232
		__next = ((unsigned int *)__bp)[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5233
		__this = (__this >> 1) /* & 0x7FFFFFF */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5234
		__this |= __next << 31;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5235
		((unsigned int *)__bp)[0] = __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5236
		__this = __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5237
		__bp += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5238
		__idx += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5239
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5240
	    if (__idx < (__nBytes - 2)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5241
		__this = ((unsigned short *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5242
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5243
		__next = ((unsigned short *)__bp)[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5244
		__this = (__this >> 1) /* & 0x7FFFFFF */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5245
		__this |= __next << 15;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5246
		((unsigned short *)__bp)[0] = __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5247
		__this = __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5248
		__bp += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5249
		__idx += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5250
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5251
	}
15326
7cc303092044 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15312
diff changeset
  5252
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5253
	if (sizeof(unsigned int) == 4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5254
	    int __endIndex = __nBytes - 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5255
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5256
	    if (__idx < __endIndex) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5257
		__this = ((unsigned int *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5258
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5259
		while (__idx < __endIndex) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5260
		    __next = ((unsigned int *)__bp)[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5261
		    __this = (__this >> 1) /* & 0x7FFFFFF */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5262
		    __this |= __next << 31;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5263
		    ((unsigned int *)__bp)[0] = __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5264
		    __this = __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5265
		    __bp += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5266
		    __idx += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5267
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5268
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5269
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5270
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  5271
#endif
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5272
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5273
	__this = __bp[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5274
	while (__idx < __nBytes) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5275
	    __next = __bp[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5276
	    __this >>= 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5277
	    __this |= __next << 7;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5278
	    __bp[0] = __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5279
	    __this = __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5280
	    __bp++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5281
	    __idx++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5282
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5283
	__bp[0] = __this >> 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5284
	RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5285
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5286
%}.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5287
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5288
    prevBit := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5289
    digitByteArray size to:1 by:-1 do:[:idx |
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5290
	|thisByte|
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5291
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5292
	thisByte := digitByteArray at:idx.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5293
	digitByteArray at:idx put:((thisByte bitShift:-1) bitOr:prevBit).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5294
	prevBit := (thisByte bitAnd:1) bitShift:7.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5295
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5296
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5297
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5298
     100000 asLargeInteger div2
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5299
     1000000000000000000000000000 div2
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5300
     10000000000000000000000000000000000000000000 div2
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5301
    "
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5302
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5303
    "Modified: 5.11.1996 / 16:12:56 / cg"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5304
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5305
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5306
mul2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5307
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5308
       destructively multiply the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5309
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5310
    |nBytes "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5311
     b      "{ Class: SmallInteger }"
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5312
     t prevBit|
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5313
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5314
    nBytes := digitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5315
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5316
    b := digitByteArray at:nBytes.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5317
    (b bitAnd:16r80) ~~ 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5318
	"/ need another byte
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5319
	nBytes := nBytes + 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5320
	t := ByteArray uninitializedNew:nBytes.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5321
	t replaceFrom:1 to:nBytes-1 with:digitByteArray startingAt:1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5322
	t at:nBytes put:0.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5323
	digitByteArray := t.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5324
    ].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5325
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5326
%{
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5327
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5328
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5329
    if (__isByteArray(__digits)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5330
	int __nBytes = __intVal(nBytes);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5331
	unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5332
	unsigned INT __carry = 0, __newCarry;
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5333
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5334
#if defined(__LSBFIRST__)
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5335
# if (__POINTER_SIZE__ == 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5336
	if (sizeof(unsigned INT) == 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5337
	    while (__nBytes >= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5338
		unsigned INT __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5339
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5340
		__this = ((unsigned INT *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5341
		__newCarry = (__this >> 63) /* & 1 */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5342
		((unsigned INT *)__bp)[0] = (__this << 1) | __carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5343
		__carry = __newCarry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5344
		__bp += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5345
		__nBytes -= 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5346
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5347
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5348
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5349
	if (sizeof(unsigned int) == 4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5350
	    while (__nBytes >= 4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5351
		unsigned int __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5352
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5353
		__this = ((unsigned int *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5354
		__newCarry = (__this >> 31) /* & 1 */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5355
		((unsigned int *)__bp)[0] = (__this << 1) | __carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5356
		__carry = __newCarry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5357
		__bp += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5358
		__nBytes -= 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5359
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5360
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5361
	if (__nBytes >= 2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5362
	    unsigned short __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5363
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5364
	    __this = ((unsigned short *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5365
	    __newCarry = (__this >> 15) /* & 1 */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5366
	    ((unsigned short *)__bp)[0] = (__this << 1) | __carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5367
	    __carry = __newCarry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5368
	    __bp += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5369
	    __nBytes -= 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5370
	}
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5371
#endif /* LSBFIRST */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5372
	while (__nBytes) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5373
	    unsigned char __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5374
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5375
	    __this = __bp[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5376
	    __newCarry = (__this >> 7) /* & 1 */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5377
	    __bp[0] = (__this << 1) | __carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5378
	    __carry = __newCarry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5379
	    __bp++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5380
	    __nBytes--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5381
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5382
	RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5383
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5384
%}.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5385
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5386
    prevBit := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5387
    1 to:digitByteArray size do:[:idx |
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5388
	|thisByte|
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5389
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5390
	thisByte := digitByteArray at:idx.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5391
	digitByteArray at:idx put:(((thisByte bitShift:1) bitAnd:16rFF) bitOr:prevBit).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5392
	prevBit := (thisByte bitShift:-7) bitAnd:1.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5393
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5394
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5395
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5396
     100000 asLargeInteger mul2
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5397
     16r7FFFFFFFFFFF copy mul2 hexPrintString
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5398
     16rFFFFFFFFFFFF copy mul2 hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5399
     16r7FFFFFFFFFFFFF copy mul2 hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5400
     16rFFFFFFFFFFFFFF copy mul2 hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5401
     10000000000000000000000000000 mul2
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5402
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5403
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5404
    "Modified: 5.11.1996 / 16:37:32 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5405
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5406
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5407
mul256
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5408
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5409
       destructively multiply the receiver by 256."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5410
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5411
    |newDigits newSize|
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5412
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5413
    newSize := digitByteArray size + 1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5414
    newDigits := ByteArray uninitializedNew:newSize.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5415
    newDigits replaceBytesFrom:2 to:newSize with:digitByteArray startingAt:1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5416
    newDigits at:1 put:0.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5417
    digitByteArray := newDigits
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5418
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5419
    "Modified: / 20.5.1999 / 09:16:42 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5420
!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5421
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5422
numberOfDigits:nDigits
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5423
    "allocate space for nDigits bytes of magnitude"
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  5424
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5425
    digitByteArray := ByteArray new:nDigits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5426
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5427
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5428
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5429
numberOfDigits:nDigits sign:newSign
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5430
    "allocate space for nDigits bytes of magnitude"
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5431
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5432
    digitByteArray := ByteArray new:nDigits.
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5433
    sign := newSign.
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5434
!
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5435
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5436
setDigits:digits
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5437
    "set the digits from the lsb-ordered digit-bytes"
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  5438
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5439
    digitByteArray := digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5440
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5441
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5442
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5443
setDigits:digits sign:newSign
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5444
    "set the digits from the lsb-ordered digit-bytes"
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5445
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5446
    digitByteArray := digits.
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5447
    sign := newSign.
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5448
!
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5449
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5450
setSign:aNumber
19260
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5451
    "destructively change the sign of the receiver.
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5452
     Return the compressed integer (smallinteger if possible)"
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5453
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5454
    sign := aNumber.
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5455
%{
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5456
    if (aNumber == __MKSMALLINT(-1)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5457
	if (__byteArraySize(__INST(digitByteArray)) == sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5458
	    if ( ((INT *)(__byteArrayVal(__INST(digitByteArray))))[0] == -_MIN_INT) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5459
		RETURN(__MKSMALLINT(_MIN_INT));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5460
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5461
	}
19260
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5462
    }
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5463
%}.
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5464
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5465
    "
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5466
     (LargeInteger digitBytes:#[0 0 0 64]) setSign:-1
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5467
    "
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5468
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5469
    "Modified (comment): / 26-02-2016 / 22:40:27 / cg"
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5470
!
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5471
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5472
sign:aNumber
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5473
    <resource: #obsolete>
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5474
    "destructively change the sign of the receiver"
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5475
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5476
    ^ self setSign:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5477
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5478
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5479
!LargeInteger methodsFor:'queries'!
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5480
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5481
nextPowerOf2
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5482
    "return the power of 2 at or above the receiver.
19059
687547192a05 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19052
diff changeset
  5483
     Notice, that for a powerOf2, the receiver is returned.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5484
     Also notice, that (because it is used for padding),
19059
687547192a05 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19052
diff changeset
  5485
     0 is returned for zero."
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5486
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5487
    |newBytes nBytes hi|
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5488
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5489
    "/ assume I am normalized
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5490
    nBytes := digitByteArray size.
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5491
    hi := digitByteArray at:nBytes.
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5492
    self assert:(hi ~~ 0).
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5493
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5494
    newBytes := ByteArray new:(nBytes) withAll:16rFF.
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5495
    (hi isPowerOf:2) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5496
	newBytes at:nBytes put:((hi bitShift:1)- 1).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5497
    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5498
	newBytes at:nBytes put:(hi nextPowerOf2 - 1).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5499
    ].
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5500
    ^ (LargeInteger digitBytes:newBytes) + 1
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5501
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5502
    "
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5503
     100 factorial nextPowerOf2  isPowerOf:2
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5504
     1000 factorial nextPowerOf2  isPowerOf:2
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5505
     Time millisecondsToRun:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5506
	 |v|
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5507
	 v := 1000 factorial.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5508
	 1000 timesRepeat:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5509
	    v nextPowerOf2
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5510
	 ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5511
     ]
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5512
    "
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5513
! !
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5514
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5515
!LargeInteger methodsFor:'testing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5516
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5517
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5518
    "return true if the receiver is even"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5519
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5520
%{  /* NOCONTEXT */
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5521
#ifdef __SCHTEAM__
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5522
    return context._RETURN( ((STLargeInteger)self).isEven() ? STObject.True : STObject.False);
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5523
#else
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5524
    OBJ digits = __INST(digitByteArray);
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5525
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5526
    if (__isByteArray(digits)){
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5527
	if (__byteArraySize(digits) > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5528
	    unsigned char b = __ByteArrayInstPtr(digits)->ba_element[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5529
	    RETURN( (b & 1) ? false : true );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5530
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5531
    }
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5532
#endif
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5533
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5534
    ^ (digitByteArray at:1) even
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5535
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5536
    "
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5537
     16r100000000000000000001 even
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5538
     16r100000000000000000001 odd
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5539
     16r100000000000000000000 even
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5540
     16r100000000000000000000 odd
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5541
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5542
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5543
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5544
negative
18855
85ed6541937d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18848
diff changeset
  5545
    "return true, if the receiver is less than zero"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5546
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5547
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  5548
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5549
    return context._RETURN( ((STLargeInteger)self).largeValue.signum() < 0 ? STObject.True : STObject.False);
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5550
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5551
%}.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5552
    ^ (sign < 0)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5553
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5554
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5555
odd
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5556
    "return true if the receiver is odd"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5557
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5558
%{  /* NOCONTEXT */
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5559
#ifdef __SCHTEAM__
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5560
    return context._RETURN( ((STLargeInteger)self).isEven() ? STObject.False : STObject.True);
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5561
#else
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5562
    OBJ digits = __INST(digitByteArray);
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5563
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5564
    if (__isByteArray(digits)){
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5565
	if (__byteArraySize(digits) > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5566
	    unsigned char b = __ByteArrayInstPtr(digits)->ba_element[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5567
	    RETURN( (b & 1) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5568
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5569
    }
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5570
#endif
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5571
%}.
1983
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  5572
    ^ (digitByteArray at:1) odd
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  5573
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  5574
    "Modified: 18.11.1996 / 22:19:19 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5575
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5576
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5577
positive
18855
85ed6541937d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18848
diff changeset
  5578
    "return true, if the receiver is greater or equal to zero (not negative)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5579
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5580
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  5581
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5582
    return context._RETURN( ((STLargeInteger)self).largeValue.signum() >= 0 ? STObject.True : STObject.False);
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5583
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5584
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5585
    ^ (sign >= 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5586
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5587
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5588
sign
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7446
diff changeset
  5589
    "return the sign of the receiver (-1, 0 or 1)"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5590
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5591
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  5592
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5593
    return context._RETURN( STInteger._new( ((STLargeInteger)self).largeValue.signum() ));
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5594
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5595
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5596
    ^ sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5597
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5598
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5599
strictlyPositive
18855
85ed6541937d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18848
diff changeset
  5600
    "return true, if the receiver is greater than zero"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5601
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5602
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  5603
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5604
    return context._RETURN( ((STLargeInteger)self).largeValue.signum() > 0 ? STObject.True : STObject.False);
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5605
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5606
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5607
    ^ (sign > 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5608
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5609
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  5610
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5611
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5612
version
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
  5613
    ^ '$Header$'
12121
38c8767f98f2 changed: #bitAnd:
Claus Gittinger <cg@exept.de>
parents: 11959
diff changeset
  5614
!
38c8767f98f2 changed: #bitAnd:
Claus Gittinger <cg@exept.de>
parents: 11959
diff changeset
  5615
38c8767f98f2 changed: #bitAnd:
Claus Gittinger <cg@exept.de>
parents: 11959
diff changeset
  5616
version_CVS
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
  5617
    ^ '$Header$'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5618
! !
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  5619