LargeInteger.st
author Claus Gittinger <cg@exept.de>
Wed, 13 Feb 2019 22:10:53 +0100
changeset 23735 77363fc65861
parent 23497 3e74a0ec2026
child 23941 fc073731d932
permissions -rw-r--r--
#FEATURE by cg class: OrderedDictionary changed: #copyValuesFrom:to: class: OrderedDictionary class changed: #version_CVS
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
21820
3825bcd2e2c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21488
diff changeset
   318
!LargeInteger class methodsFor:'coercing & converting'!
3825bcd2e2c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21488
diff changeset
   319
3825bcd2e2c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21488
diff changeset
   320
coerce:aNumber
3825bcd2e2c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21488
diff changeset
   321
    "convert the argument aNumber into an instance of the receiver's class and return it."
3825bcd2e2c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21488
diff changeset
   322
3825bcd2e2c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21488
diff changeset
   323
    ^ aNumber asLargeInteger
3825bcd2e2c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21488
diff changeset
   324
! !
21488
19a79c086cc8 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20418
diff changeset
   325
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   326
!LargeInteger class methodsFor:'queries'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   327
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   328
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   329
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   330
     Here, true is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   331
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   332
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   333
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   334
    "Modified: 23.4.1996 / 15:59:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   335
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   336
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   337
!LargeInteger methodsFor:'arithmetic'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   338
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   339
* aNumber
11731
f3adbab61060 comment
Claus Gittinger <cg@exept.de>
parents: 11723
diff changeset
   340
    "return the product of the receiver and the argument."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   341
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   342
    |otherSign numberClass|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   343
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   344
    (sign == 0) ifTrue:[^ 0].  "cannot happen if correctly normalized"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   345
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
     this is the common case, multiplying with SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   348
     Use a special method for this case ...
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   349
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   350
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   351
	^ self productFromInteger:aNumber
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   352
    ].
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
     if the argument is not a largeInteger, coerce
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   356
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   357
    (numberClass == self class) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   358
	^ self retry:#* coercing:aNumber
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   361
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   362
    (sign == otherSign) ifTrue:[^ self absMul:aNumber].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   363
    (otherSign == 0) ifTrue:[^ 0].
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   364
    ^ (self absMul:aNumber) setSign:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   365
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   366
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   367
+ aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   368
    "return the sum of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   369
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   370
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   371
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   372
    (sign == 0) ifTrue:[^ aNumber].  "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   373
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   374
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   375
     this is the common case, adding a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   376
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   377
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   378
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   379
	^ self sumFromInteger:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   380
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   381
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   382
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   383
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   384
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   385
    (numberClass == self class) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   386
	^ self retry:#+ coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   387
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   388
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   389
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   390
    (sign > 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   391
	"I am positive"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   392
	(otherSign > 0) ifTrue:[^ self absPlus:aNumber sign:1].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   393
	(otherSign < 0) ifTrue:[^ self absMinus:aNumber sign:1].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   394
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   395
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   396
    "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
   397
    (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
   398
    (otherSign < 0) ifTrue:[^ self absPlus:aNumber sign:-1].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   399
    ^ self
357
claus
parents: 345
diff changeset
   400
claus
parents: 345
diff changeset
   401
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   402
     SmallInteger maxVal
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   403
     SmallInteger maxVal + 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   404
     SmallInteger maxVal + 2
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   405
     SmallInteger minVal
357
claus
parents: 345
diff changeset
   406
     SmallInteger minVal - 1
claus
parents: 345
diff changeset
   407
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   408
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   409
    "Modified: / 9.1.1998 / 13:26:28 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   410
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   411
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   412
- aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   413
    "return the difference of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   414
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   415
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   416
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   417
    (sign == 0) ifTrue:[^ aNumber negated].     "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   418
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   419
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   420
     this is the common case, subtracting a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   421
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   422
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   423
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   424
	sign > 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   425
	    aNumber > 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   426
		^ self absFastMinus:aNumber sign:1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   427
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   428
	    ^ self absFastPlus:aNumber sign:1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   429
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   430
	aNumber > 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   431
	    ^ self absFastPlus:aNumber sign:-1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   432
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   433
	^ self absFastMinus:aNumber sign:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   434
    ].
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
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   438
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   439
    (numberClass == self class) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   440
	^ self retry:#- coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   441
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   442
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   443
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   444
    (sign > 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   445
	"I am positive"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   446
	(otherSign > 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   447
	    "+large - +large"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   448
	    ^ self absMinus:aNumber sign:1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   449
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   450
	(otherSign < 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   451
	    "+large - -large"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   452
	    ^ self absPlus:aNumber sign:1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   453
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   454
	"should not happen"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   455
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   456
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   457
    "I am negative"
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   458
    (otherSign > 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   459
	"-large - +large"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   460
	^ self absPlus:aNumber sign:-1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   461
    ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   462
    (otherSign < 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   463
	"-large - -large"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   464
	^ self absMinus:aNumber sign:-1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   465
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   466
    ^ self
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   467
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   468
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   469
     12345678901234567890 - 0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   470
     12345678901234567890 - 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   471
     12345678901234567890 - -1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   472
     -12345678901234567890 - 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   473
     -12345678901234567890 - -1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   474
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   475
     12345678901234567890 - 12345678901234567880
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   476
     12345678901234567890 - 12345000000000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   477
     12345678901234567890 - -87654321098765432110
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   478
     -12345678901234567890 - 87654321098765432110
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   479
     -12345678901234567890 - -12345678901234567880
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   480
     -12345678901234567890 - -12345678901234567980
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   481
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   482
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   483
    "Modified: 20.10.1996 / 18:42:16 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   484
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   485
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   486
/ aNumber
1065
77b25fb9f9d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   487
    "return the quotient of the receiver and the argument, aNumber"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   488
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   489
    aNumber isInteger ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   490
	^ Fraction numerator:self denominator:aNumber
14766
ae12897bef55 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 13992
diff changeset
   491
    ].
ae12897bef55 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 13992
diff changeset
   492
    aNumber isFraction ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   493
	^ Fraction numerator:(self * aNumber denominator) denominator:(aNumber numerator)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   494
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   495
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   496
    "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
   497
    ^ (self asFloat / aNumber asFloat)
2793
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   498
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   499
    "Modified: 28.7.1997 / 19:07:55 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   500
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   501
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   502
// aNumber
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
   503
    "return the integer part of the quotient of the receiver's value
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
   504
     and the argument's value.
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   505
     The result is truncated toward negative infinity
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   506
     and will be negative, if the operands signs differ.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   507
     The following is always true:
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   508
	(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   509
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   510
     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
   511
     Especially surprising (because of truncation toward negative infinity):
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   512
	-1 // 10 -> -1 (because -(1/10) is truncated towards next smaller integer, which is -1.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   513
	-10 // 3 -> -4 (because -(10/3) is truncated towards next smaller integer, which is -4.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   514
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   515
     See #quo: which truncates toward zero and returns -2 in the above case
20340
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   516
     and #rem: which is the corresponding remainder."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   517
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   518
    |nrClass divMod quo|
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   519
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   520
    nrClass := aNumber class.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   521
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   522
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   523
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   524
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   525
    "
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   526
    ((nrClass == SmallInteger) or:[ nrClass == self class]) ifFalse:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   527
	^ self retry:#// coercing:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   528
    ].
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   529
    divMod := self absDivMod:aNumber.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   530
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   531
    quo := divMod at:1.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   532
    (sign == aNumber sign) ifFalse:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   533
	"/ adjust for truncation if negative and there is a remainder ...
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   534
	"/ be careful: there is one special case to care for here:
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   535
	"/ if quo is maxInt+1, the negation can be represented as a smallInt.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   536
	quo := quo setSign:-1.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   537
	(divMod at:2) == 0 ifFalse:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   538
	    ^ quo - 1
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   539
	].
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   540
"/        quo digitLength == SmallInteger maxBytes ifTrue:[
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   541
"/            ^ quo compressed
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   542
"/        ].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   543
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   544
    ^ quo
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   545
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   546
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   547
     (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
   548
     (-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
   549
     (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
   550
     (-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
   551
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   552
     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
   553
     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
   554
     16rfffffffff // 16r001fffff  =  32768 ifFalse:[self halt].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   555
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   556
     900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   557
     -900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   558
     900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   559
     -900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   560
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   561
     9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   562
     -9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   563
     9000000000 quo: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   564
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   565
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   566
     0 // 40000000000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   567
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   568
19260
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
   569
    "Modified: / 27-04-1999 / 19:50:26 / stefan"
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
   570
    "Modified: / 26-02-2016 / 22:28:27 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   571
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   572
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   573
\\ aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   574
    "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
   575
     negative infinity.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   576
     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
   577
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   578
     The returned remainder has the same sign as aNumber.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   579
     The following is always true:
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   580
        (receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   581
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   582
     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
   583
     Especially surprising:
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   584
        -1 \\ 10 -> 9  (because -(1/10) is truncated towards next smaller integer, which is -1,
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   585
                        and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   586
        -10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   587
                        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
   588
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   589
     See #rem: which is the corresponding remainder for division via #quo:.
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   590
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   591
     Redefined here for speed."
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   592
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   593
    |rem negativeDivisor nrClass|
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   594
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   595
    nrClass := aNumber class.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   596
    ((nrClass == SmallInteger) or:[nrClass == self class]) ifFalse:[
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   597
        ^ self retry:#\\ coercing:aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   598
    ].
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   599
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   600
    rem := self absMod:aNumber.
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   601
    rem ~~ 0 ifTrue:[
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   602
        negativeDivisor := aNumber negative.
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   603
        negativeDivisor ifTrue:[
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   604
            rem := rem setSign:-1
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   605
        ].
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   606
        (self negative ~~ negativeDivisor) ifTrue:[
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   607
            "different sign, so remainder would have been negative.
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   608
             rem has been rounded toward zero, this code will simulate
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   609
             rounding to negative infinity."
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   610
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   611
            rem := aNumber - rem.
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   612
        ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   613
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   614
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   615
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   616
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   617
     (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
   618
     (-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
   619
     (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
   620
     (-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
   621
     (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
   622
     (-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
   623
     (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
   624
     (-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
   625
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   626
     9000000000 \\ 7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   627
     -9000000000 \\ 7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   628
     9000000000 \\ -7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   629
     -9000000000 \\ -7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   630
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   631
     900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   632
     -900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   633
     900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   634
     -900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   635
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   636
     9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   637
     -9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   638
     9000000000 rem: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   639
     -9000000000 rem: -4000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   640
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   641
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   642
    "Modified: / 27-04-1999 / 20:03:40 / stefan"
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   643
    "Modified: / 05-07-2017 / 16:12:47 / cg"
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   644
!
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   645
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   646
abs
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   647
    "return my absolute value. redefined for speed."
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   648
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   649
    sign >= 0 ifTrue:[^ self].
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   650
    ^ self negated
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   651
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   652
    "Created: / 26.10.1999 / 21:28:06 / stefan"
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   653
!
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   654
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   655
divMod:aNumber
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
   656
    "return an array filled with
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   657
	(self // aNumber) and (self \\ aNumber).
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   658
     The returned remainder has the same sign as aNumber.
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   659
     The following is always true:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   660
	(receiver // something) * something + (receiver \\ something) = receiver
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   661
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   662
     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
   663
     Especially surprising:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   664
	-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
   665
			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
   666
	-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
   667
			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
   668
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
   669
     This is redefined here for more performance
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   670
     (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
   671
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   672
    |nrClass|
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   673
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   674
    ((self < 0) or:[aNumber <= 0]) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   675
	"/ this is rubbish
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   676
	^ super divMod:aNumber
17035
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   677
    ].
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   678
4b6d41ac41b6 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16916
diff changeset
   679
    "/ only handle the common case here
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   680
    nrClass := aNumber class.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   681
    (nrClass == SmallInteger) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   682
	(nrClass == self class) ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   683
	    ^ super divMod:aNumber
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   684
	].
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   685
    ].
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   686
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   687
    ^ self absDivMod:aNumber.
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   688
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   689
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   690
     9000000000 // 4000000000   => 2
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   691
     9000000000 \\ 4000000000   => 1000000000
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   692
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   693
     9000000000 divMod: 4000000000   => #(2 1000000000)
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   694
     -9000000000 divMod: 4000000000   => #(-3 3000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   695
     9000000000 divMod: -4000000000   => #(-3 -3000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   696
     -9000000000 divMod: -4000000000   => #(2 -1000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   697
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   698
     9000000000000000000 absDivMod: 400000000000000   => #(22500 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   699
     -9000000000000000000 absDivMod: 400000000000000   => #(22500 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   700
     9000000000000000000 absDivMod: -400000000000000   => #(22500 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   701
     -9000000000000000000 absDivMod: -400000000000000   => #(22500 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   702
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   703
     9000000000000000000 absDivMod: 4000000000000000   => #(2250 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   704
     -9000000000000000000 absDivMod: 4000000000000000   => #(2250 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   705
     9000000000000000000 absDivMod: -4000000000000000   => #(2250 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   706
     -9000000000000000000 absDivMod: -4000000000000000   => #(2250 0)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   707
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   708
     9000000000000000000 absDivMod: 4000000000000000000   => #(2 1000000000000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   709
     -9000000000000000000 absDivMod: 4000000000000000000   => #(2 1000000000000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   710
     9000000000000000000 absDivMod: -4000000000000000000   => #(2 1000000000000000000)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   711
     -9000000000000000000 absDivMod: -4000000000000000000   => #(2 1000000000000000000)
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   712
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   713
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   714
    "Created: / 29.10.1996 / 21:22:05 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   715
    "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
   716
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   717
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   718
negated
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
   719
    "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
   720
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   721
    |newNumber sz|
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   722
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   723
    (sign == 0) ifTrue:[^ 0].
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   724
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   725
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   726
     special case for SmallInteger minVal
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   727
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   728
    sign == 1 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   729
	sz := digitByteArray size.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   730
%{
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   731
#ifdef __SCHTEAM__
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   732
#else /* not SCHTEAM */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   733
	int idx;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   734
	unsigned char *bp;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   735
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   736
	bp = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   737
	idx = __intVal(sz);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   738
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   739
	while ((idx > 1) && (bp[idx-1] == 0)) idx--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   740
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   741
	if (idx == sizeof(INT)) {
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   742
# if defined(__LSBFIRST__)
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   743
#  if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   744
	    if ( ((unsigned INT *)bp)[0] == 0x4000000000000000L)
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   745
#  else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   746
	    if ( ((unsigned INT *)bp)[0] == 0x40000000)
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   747
#  endif
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   748
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   749
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   750
	     * generic code
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   751
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   752
	    if ((bp[idx-1] == 0x40)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   753
	     && (bp[idx-2] == 0)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   754
	     && (bp[idx-3] == 0)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   755
	     && (bp[idx-4] == 0)
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   756
#  if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   757
	     && (bp[idx-5] == 0)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   758
	     && (bp[idx-6] == 0)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   759
	     && (bp[idx-7] == 0)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   760
	     && (bp[idx-8] == 0)
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   761
#  endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   762
	    )
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   763
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   764
	    {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   765
		RETURN (__mkSmallInteger(_MIN_INT));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   766
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   767
	}
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   768
#endif
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   769
%}.
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
   770
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   771
	sz == SmallInteger maxBytes ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   772
	  (digitByteArray at:1) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   773
	   (digitByteArray at:2) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   774
	    (digitByteArray at:3) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   775
		SmallInteger maxBytes == 8 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   776
		  (digitByteArray at:4) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   777
		   (digitByteArray at:5) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   778
		    (digitByteArray at:6) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   779
		     (digitByteArray at:7) == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   780
		      (digitByteArray at:8) == 16r40 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   781
			^ SmallInteger minVal
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   782
		      ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   783
		     ]
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
		] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   788
		  (digitByteArray at:4) == 16r40 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   789
		    ^ SmallInteger minVal
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   790
		  ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   791
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   792
	    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   793
	   ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   794
	  ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   795
	].
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   796
    ].
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
   797
    "/ cg - can share the digits ...
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
   798
    newNumber := self class digitBytes:digitByteArray sign:(sign negated).
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   799
    ^ newNumber
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   800
!
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   801
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   802
quo:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   803
    "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
   804
     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
   805
     truncates toward negative infinity).
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   806
     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
   807
     The following is always true:
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   808
	(receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
20340
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   809
     For positive results, this is the same as #//,
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   810
     for negative results, the remainder is ignored.
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   811
     I.e.: '9 // 4 = 2' and '-9 // 4 = -3'
56c577d27514 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19902
diff changeset
   812
     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
   813
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   814
    |nrClass quo |
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   815
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   816
    nrClass := aNumber class.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   817
    ((nrClass == SmallInteger) or:[ nrClass == self class] ) ifFalse:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   818
	^ self retry:#quo: coercing:aNumber
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   819
    ].
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   820
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   821
    quo := (self absDivMod:aNumber) at:1.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   822
    (sign == aNumber sign) ifTrue:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
   823
	^ quo
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   824
    ].
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   825
    ^ quo setSign:-1
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   826
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   827
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   828
     900 // 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   829
     -900 // 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   830
     900 // -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   831
     -900 // -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   832
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   833
     9000000000 // 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   834
     -9000000000 // 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   835
     9000000000 // -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   836
     -9000000000 // -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   837
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   838
     900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   839
     -900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   840
     900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   841
     -900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   842
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   843
     9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   844
     -9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   845
     9000000000 quo: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   846
     -9000000000 quo: -4000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   847
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   848
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   849
    "Modified: / 5.11.1996 / 14:14:17 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   850
    "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
   851
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   852
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   853
rem:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   854
    "return the remainder of division of the receiver by the argument, aNumber.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   855
     The returned remainder has the same sign as the receiver.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   856
     The following is always true:
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   857
        (receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   858
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   859
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   860
    |nrClass rem|
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   861
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   862
    nrClass := aNumber class.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   863
    ((nrClass == SmallInteger) or:[ nrClass == self class ]) ifFalse:[
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   864
        ^ self retry:#rem coercing:aNumber
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   865
    ].
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   866
    rem := self absMod:aNumber.
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
   867
    rem ~~ 0 ifTrue:[
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   868
        sign < 0 ifTrue:[
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   869
            ^ rem setSign:-1
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   870
        ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   871
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   872
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   873
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   874
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   875
     900 \\ 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   876
     -900 \\ 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   877
     900 \\ -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   878
     -900 \\ -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   879
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   880
     9000000000 \\ 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   881
     -9000000000 \\ 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   882
     9000000000 \\ -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   883
     -9000000000 \\ -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   884
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   885
     900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   886
     -900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   887
     900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   888
     -900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   889
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   890
     9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   891
     -9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   892
     9000000000 rem: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   893
     -9000000000 rem: -4000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   894
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   895
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   896
    "Modified: / 29-04-1999 / 11:26:51 / stefan"
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
   897
    "Modified: / 05-07-2017 / 16:13:33 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   898
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   899
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   900
!LargeInteger methodsFor:'bit operators'!
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   901
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   902
bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   903
    "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
   904
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   905
%{  /* NOCONTEXT */
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   906
    if (__isSmallInteger(anInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   907
	INT v2 = __intVal(anInteger);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   908
	INT v1;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   909
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   910
	v1 = *(INT *)(__byteArrayVal(__INST(digitByteArray)));
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   911
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   912
	unsigned char *digits = (unsigned char *)(__byteArrayVal(__INST(digitByteArray)));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   913
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   914
	v1 = digits[0] & 0xFF;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   915
	v1 = v1 | ((digits[1] & 0xFF)<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   916
	v1 = v1 | ((digits[2] & 0xFF)<<16);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   917
	v1 = v1 | ((digits[3] & 0xFF)<<24);
11605
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   918
# if (__POINTER_SIZE__ == 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   919
	v1 = v1 | ((digits[4] & 0xFF)<<32);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   920
	v1 = v1 | ((digits[5] & 0xFF)<<40);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   921
	v1 = v1 | ((digits[6] & 0xFF)<<48);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   922
	v1 = v1 | ((digits[7] & 0xFF)<<56);
11605
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   923
 #endif
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   924
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   925
	RETURN ( __mkSmallInteger(v1 & v2) );
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   926
    }
11959
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   927
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   928
    if (__isLargeInteger(anInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   929
	OBJ _myDigitByteArray = __INST(digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   930
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(anInteger)->l_digits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   931
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   932
	if (__isByteArray(_myDigitByteArray)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   933
	 && __isByteArray(_otherDigitByteArray)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   934
	    unsigned char *pDigits1, *pDigits2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   935
	    int size1, size2, minSize;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   936
	    union {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   937
		double d;                    // force align
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   938
		unsigned char chars[2048+8];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   939
	    } buffer;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   940
	    unsigned char *pRslt;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   941
	    OBJ newDigits, newLarge;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   942
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   943
	    pDigits1 = (unsigned char *)(__byteArrayVal(_myDigitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   944
	    pDigits2 = (unsigned char *)(__byteArrayVal(_otherDigitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   945
	    pRslt = (void *)(buffer.chars);
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
	    size1 = __byteArraySize(_myDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   948
	    size2 = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   949
	    minSize = (size1 < size2) ? size1 : size2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   950
	    if (minSize <= sizeof(buffer.chars)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   951
		int n = minSize;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   952
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   953
	    /* 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
   954
#define x__USE_MMX__
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   955
#ifdef __USE_MMX__
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   956
#ifdef __VISUALC__
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   957
		if (((INT)pRslt & 7) == 0) {    // 8-byte aligned
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   958
		    if (((INT)pDigits1 & 7) == ((INT)pDigits2 & 7)) {   // same align
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   959
			while (((INT)pDigits1 & 7) && (n >= sizeof(int))) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   960
			    ((int *)pRslt)[0] = ((int *)pDigits1)[0] & ((int *)pDigits2)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   961
			    pRslt += sizeof(int);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   962
			    pDigits1 += sizeof(int);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   963
			    pDigits2 += sizeof(int);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   964
			    pDigits2 += sizeof(int);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   965
			    n -= sizeof(int);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   966
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   967
			for (; n >= 8; n -= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   968
			    __asm {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   969
				mov eax, pDigits1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   970
				movq mm0, [eax]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   971
				mov eax, pDigits2
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   972
				movq mm1, [eax]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   973
				pand mm0, mm1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   974
				mov eax, pRslt
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   975
				movq [eax], mm0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   976
			    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   977
			    pDigits1 += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   978
			    pDigits2 += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   979
			    pRslt += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   980
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   981
			__asm {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   982
			    emms ; switch back to FPU state.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   983
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   984
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   985
		}
11959
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   986
#endif /* __VISUALC__ */
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   987
#endif /* __USE_MMX__ */
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
   988
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   989
		for (; n >= sizeof(INT)*4; n -= sizeof(INT)*4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   990
		    ((INT *)pRslt)[0] = ((INT *)pDigits1)[0] & ((INT *)pDigits2)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   991
		    ((INT *)pRslt)[1] = ((INT *)pDigits1)[1] & ((INT *)pDigits2)[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   992
		    ((INT *)pRslt)[2] = ((INT *)pDigits1)[2] & ((INT *)pDigits2)[2];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   993
		    ((INT *)pRslt)[3] = ((INT *)pDigits1)[3] & ((INT *)pDigits2)[3];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   994
		    pRslt += sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   995
		    pDigits1 += sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   996
		    pDigits2 += sizeof(INT)*4;
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 >= sizeof(INT); n -= sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
   999
		    ((INT *)pRslt)[0] = ((INT *)pDigits1)[0] & ((INT *)pDigits2)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1000
		    pRslt += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1001
		    pDigits1 += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1002
		    pDigits2 += sizeof(INT);
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
		for (; n > 0; n--) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1005
		    *pRslt = *pDigits1 & *pDigits2;
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
		    pDigits1++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1008
		    pDigits2++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1009
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1010
		// normalize
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1011
		while ((pRslt[-1]==0) && (pRslt > buffer.chars)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1012
		    pRslt--;
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
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1015
		// allocate result
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1016
		n = pRslt-buffer.chars;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1017
		if (n <= sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1018
		    INT val = 0;
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
		    // make it a smallInteger / 32bitInteger
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1021
		    while (n > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1022
			val = (val << 8) + buffer.chars[--n];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1023
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1024
		    RETURN (__MKUINT(val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1025
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1026
		newDigits = __MKBYTEARRAY(buffer.chars, n);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1027
		if (newDigits) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1028
		    __PROTECT__(newDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1029
		    newLarge = __STX___new(sizeof(struct __LargeInteger));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1030
		    __UNPROTECT__(newDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1031
		    if (newLarge) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1032
			__InstPtr(newLarge)->o_class = LargeInteger; __STORE(newLarge, LargeInteger);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1033
			__LargeIntegerInstPtr(newLarge)->l_digits = newDigits; __STORE(newLarge, newDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1034
			__LargeIntegerInstPtr(newLarge)->l_sign = __MKSMALLINT(1);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1035
			RETURN (newLarge);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1036
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1037
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1038
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1039
	}
11959
1ff0e6f908d9 fast bitAnd
Claus Gittinger <cg@exept.de>
parents: 11927
diff changeset
  1040
    }
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1041
%}.
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1042
    ^ super bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1043
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1044
    "
6051
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
  1045
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFF) hexPrintString
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1046
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1047
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1048
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1049
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1050
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1051
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1052
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFFFFFF) hexPrintString
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1053
    "
6051
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
  1054
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
  1055
    "Modified: / 26.9.2001 / 17:34:03 / cg"
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1056
!
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1057
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1058
bitXor:anInteger
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1059
    "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
  1060
     Here, a specially tuned version for largeInteger arguments
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1061
     (to speed up some cryptographic code)"
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1062
15626
d1cacaf45c0c class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15577
diff changeset
  1063
    |len1 len2 newBytes|
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1064
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1065
    anInteger class ~~ LargeInteger ifTrue:[^ super bitXor:anInteger].
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1066
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1067
    (len1 := anInteger digitLength) > (len2 := self digitLength) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1068
	newBytes := anInteger digitBytes copy.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1069
	newBytes bitXorBytesFrom:1 to:len2 with:digitByteArray startingAt:1
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1070
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1071
	newBytes := digitByteArray copy.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1072
	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
  1073
    ].
16124
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1074
    ^ (self class digitBytes:newBytes) compressed
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
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1077
     (16r112233445566778899 bitXor:16rFF                ) printStringRadix:16 '112233445566778866'
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1078
     (16r112233445566778899 bitXor:16rFFFFFFFFFFFFFFFF00) printStringRadix:16 'EEDDCCBBAA99887799'
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1079
     (16r112233445566778899 bitXor:16rFF0000000000000000) printStringRadix:16 'EE2233445566778899'
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1080
     (16r112233445566778899 bitXor:16r112233445566778800) printStringRadix:16 '99'
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1081
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1082
     |bigNum1 bigNum2|
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1083
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1084
     bigNum1 := 2 raisedToInteger:512.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1085
     bigNum2 := 2 raisedToInteger:510.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1086
     Time millisecondsToRun:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1087
	1000000 timesRepeat:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1088
	   bigNum1 bitXor:bigNum2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1089
	]
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1090
     ]
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1091
    "
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1092
!
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1093
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1094
lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1095
    "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
  1096
     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
  1097
     Returns 0 if no bit is set.
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1098
     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
  1099
     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
  1100
     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
  1101
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1102
    |sz   "{ Class: SmallInteger }"
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1103
     idx0 "{ Class: SmallInteger }"
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1104
     byte|
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1105
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1106
    idx0 := 1.
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1107
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1108
%{
12746
10866527a1ab changed: #lowBit
Claus Gittinger <cg@exept.de>
parents: 12121
diff changeset
  1109
    OBJ __digitByteArray = __INST(digitByteArray);
10866527a1ab changed: #lowBit
Claus Gittinger <cg@exept.de>
parents: 12121
diff changeset
  1110
7544
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1111
    /*
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1112
     * quickly advance over full 0-words
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1113
     */
12746
10866527a1ab changed: #lowBit
Claus Gittinger <cg@exept.de>
parents: 12121
diff changeset
  1114
    if (__isByteArray(__digitByteArray)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1115
	int __sz = __byteArraySize(__digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1116
	unsigned char *__bP = __byteArrayVal(__digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1117
	unsigned char *__bP0 = __bP;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1118
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1119
	sz = __MKSMALLINT(__sz);
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1120
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1121
#ifdef __UNROLL_LOOPS__
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1122
	while (__sz > (sizeof(INT) * 4)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1123
	    if (( ((INT *)__bP)[0]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1124
		 | ((INT *)__bP)[1]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1125
		 | ((INT *)__bP)[2]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1126
		 | ((INT *)__bP)[3] ) != 0) break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1127
	    __sz -= sizeof(INT) * 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1128
	    __bP += sizeof(INT) * 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1129
	}
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1130
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1131
	while (__sz > sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1132
	    if ( ((INT *)__bP)[0] != 0 ) break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1133
	    __sz -= sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1134
	    __bP += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1135
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1136
	while (__sz > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1137
	    unsigned int c;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1138
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1139
	    if ( (c = *__bP) != 0 ) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1140
		int bitIdx = (__bP - __bP0) * 8;
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1141
#ifdef __BSF
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1142
		{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1143
		    int index;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1144
		    int t = c;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1145
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1146
		    index = __BSF(t);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1147
		    RETURN ( __mkSmallInteger(index + 1 + bitIdx) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1148
		}
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1149
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1150
		if (c & 0x0F) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1151
		    if (c & 0x03) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1152
			if (c & 0x01) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1153
			    RETURN ( __mkSmallInteger( bitIdx + 1) );
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 + 2) );
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
		    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1158
			if (c & 0x04) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1159
			    RETURN ( __mkSmallInteger( bitIdx + 3) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1160
			} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1161
			    RETURN ( __mkSmallInteger( bitIdx + 4) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1162
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1163
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1164
		} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1165
		    if (c & 0x30) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1166
			if (c & 0x10) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1167
			    RETURN ( __mkSmallInteger( bitIdx + 5) );
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 + 6) );
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
		    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1172
			if (c & 0x40) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1173
			    RETURN ( __mkSmallInteger( bitIdx + 7) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1174
			} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1175
			    RETURN ( __mkSmallInteger( bitIdx + 8) );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1176
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1177
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1178
		}
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1179
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1180
		break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1181
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1182
	    __sz--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1183
	    __bP++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1184
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1185
	idx0 = __mkSmallInteger( __bP - __bP0 + 1 );
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1186
    }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1187
%}.
12746
10866527a1ab changed: #lowBit
Claus Gittinger <cg@exept.de>
parents: 12121
diff changeset
  1188
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1189
    "/ never actually reached
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1190
    idx0 to:sz do:[:digitIndex |
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1191
	(byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1192
	    ^ (digitIndex-1)*8 + (byte lowBit)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1193
	]
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1194
    ].
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1195
    ^ 0 "/ should not happen
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1196
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1197
    "
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  1198
     (1 bitShift:0) lowBit
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1199
     (1 bitShift:10) lowBit
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1200
     (1 bitShift:20) lowBit
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1201
     (1 bitShift:30) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1202
     (1 bitShift:30) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1203
     (1 bitShift:31) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1204
     (1 bitShift:31) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1205
     (1 bitShift:32) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1206
     (1 bitShift:32) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1207
     (1 bitShift:33) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1208
     (1 bitShift:33) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1209
     (1 bitShift:64) lowBit
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  1210
     (1 bitShift:64) highBit
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1211
     (1 bitShift:1000) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1212
     (1 bitShift:1000) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1213
     ((1 bitShift:64)-1) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1214
     ((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
  1215
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1216
     1 to:1000 do:[:idx |
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1217
	self assert:(( 1 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1218
	self assert:(( 1 bitShift:idx) lowBit = ( 1 bitShift:idx) highBit).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1219
	self assert:(( 3 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1220
	self assert:(( 7 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1221
	self assert:(( 15 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1222
	self assert:(( 31 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1223
	self assert:(( 63 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1224
	self assert:(( 127 bitShift:idx) lowBit = (idx+1)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1225
	self assert:(( 255 bitShift:idx) lowBit = (idx+1)).
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1226
     ]
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1227
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1228
     |num|
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1229
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1230
     num := (1 bitShift:1000).
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1231
     Time millisecondsToRun:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1232
	1000000 timesRepeat:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1233
	    num lowBit
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1234
	]
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1235
     ]
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1236
    "
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1237
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1238
    "Modified: 14.8.1997 / 11:55:34 / cg"
19052
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1239
! !
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1240
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1241
!LargeInteger methodsFor:'bit operators - indexed'!
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1242
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1243
bitAt:anIntegerIndex
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1244
    "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
  1245
     Notice: the result of bitAt: on negative receivers is not
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1246
	     defined in the language standard (since the implementation
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1247
	     is free to choose any internal representation for integers)"
19052
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1248
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1249
%{  /* NOCONTEXT */
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1250
    if (__isSmallInteger(anIntegerIndex)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1251
	INT idx = __smallIntegerVal(anIntegerIndex) - 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1252
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1253
	if (idx >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1254
	    int v1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1255
	    int byteOffset = idx / 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1256
	    int digitLen   = __byteArraySize(__INST(digitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1257
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1258
	    if (digitLen < byteOffset) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1259
		RETURN(__mkSmallInteger(0));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1260
	    }
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
	    v1 = (__byteArrayVal(__INST(digitByteArray)))[byteOffset];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1263
	    if (v1 & (1 << (idx % 8))) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1264
		RETURN(__mkSmallInteger(1));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1265
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1266
		RETURN(__mkSmallInteger(0));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1267
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1268
	}
19052
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1269
    }
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1270
%}.
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1271
    ^ super bitAt:anIntegerIndex
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1272
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1273
    "
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1274
     TestCase should:[ 16rFFFFFFFFFF01 bitAt:0 ] raise:Error
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1275
     TestCase assert:( 16rFFFFFFFFFF01 bitAt:49 ) == 0
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1276
     TestCase assert:( 16rFFFFFFFFFF01 bitAt:1  ) == 1
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1277
     TestCase assert:( 16rFFFFFFFFFF01 bitAt:2  ) == 0
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1278
     TestCase assert:( 16rFFFFFFFFFF02 bitAt:2  ) == 1
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1279
     TestCase assert:( 16rFFFFFFFF01FF bitAt:8  ) == 1
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1280
     TestCase assert:( 16rFFFFFFFF01FF bitAt:9  ) == 1
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1281
     TestCase assert:( 16rFFFFFFFF01FF bitAt:10 ) == 0
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1282
    "
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1283
3981835eca68 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18903
diff changeset
  1284
    "Modified: / 10-08-2010 / 12:33:04 / cg"
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1285
!
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
setBit:index
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1288
    "return a new integer, where the specified bit is on.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1289
     Bits are counted from 1 starting with the least significant.
22370
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1290
     The method's name may be misleading: the receiver is not changed,
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1291
     but a new number is returned. Should be named #withBitSet:"
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1292
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1293
    |myDigitLength newDigitLength newDigitBytes byteIndexOfBitToSet|
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
    index <= 0 ifTrue:[
22370
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1296
        ^ SubscriptOutOfBoundsSignal
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1297
                raiseRequestWith:index
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1298
                errorString:'index out of bounds'
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1299
    ].
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1300
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1301
    myDigitLength := digitByteArray size.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1302
    byteIndexOfBitToSet := ((index-1)//8)+1.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1303
    byteIndexOfBitToSet > myDigitLength ifTrue:[
22370
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1304
        newDigitLength := myDigitLength max:byteIndexOfBitToSet.
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1305
        newDigitBytes := ByteArray new:newDigitLength.
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1306
        newDigitBytes replaceFrom:1 to:myDigitLength with:digitByteArray startingAt:1.
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1307
    ] ifFalse:[
22370
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1308
        newDigitBytes := digitByteArray copy
11507
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
    newDigitBytes
22370
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1311
        at:byteIndexOfBitToSet
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1312
        put:((newDigitBytes at:byteIndexOfBitToSet) setBit:(((index-1)\\8)+1)).
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  1313
    ^ self class digitBytes:newDigitBytes sign:sign
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1314
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1315
    "
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  1316
     TestCase assert:( 16r80000000 setBit:3  ) = 16r80000004
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  1317
     TestCase assert:( 16r80000000 setBit:33 ) = 16r180000000
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1318
    "
22370
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1319
590a315a9d33 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22267
diff changeset
  1320
    "Modified (comment): / 21-11-2017 / 13:02:38 / cg"
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1321
! !
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1322
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1323
!LargeInteger methodsFor:'bit operators-32bit'!
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1324
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1325
bitInvert32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1326
    "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
  1327
     (changes the sign)"
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1328
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1329
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1330
    unsigned INT v;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1331
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1332
    v = __unsignedLongIntVal(self);
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1333
    v = ~v;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1334
#if __POINTER_SIZE__ == 8
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1335
    v &= 0xFFFFFFFFL;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1336
#endif
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1337
    RETURN ( __MKUINT(v) );
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
    ^ self primitiveFailed
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
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1342
     16r80000000 bitInvert32 hexPrintString
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1343
     16r7FFFFFFF bitInvert32 hexPrintString
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1344
     16rFFFFFFFF bitInvert32 hexPrintString
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1345
     0 bitInvert32 hexPrintString
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
!
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
bitRotate32:shiftCount
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1350
    "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
  1351
     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
  1352
     Rotates through the sign bit.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1353
     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
  1354
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1355
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1356
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1357
    unsigned INT bits;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1358
    int count;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1359
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1360
    if (__isSmallInteger(shiftCount)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1361
	count = __intVal(shiftCount);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1362
	count = count % 32;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1363
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1364
	bits = __unsignedLongIntVal(self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1365
	if (count > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1366
	    bits = (bits << count) | (bits >> (32-count));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1367
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1368
	    bits = (bits >> (-count)) | (bits << (32-(-count)));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1369
	}
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1370
#if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1371
	bits &= 0xFFFFFFFFL;
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1372
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1373
	RETURN (__MKUINT(bits));
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
    ^ self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1377
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1378
    "
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1379
     (1 bitShift32:31) rotate32:0
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1380
     (1 bitShift32:31) rotate32:1
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1381
     (1 bitShift32:31) rotate32:-1
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1382
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1383
!
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
bitShift32:shiftCount
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1386
    "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
  1387
     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
  1388
     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
  1389
     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
  1390
     or to emulate C/Java semantics.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1391
     The shift is unsigned"
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1392
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1393
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1394
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1395
    unsigned INT bits;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1396
    int count;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1397
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1398
    if (__isSmallInteger(shiftCount)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1399
	count = __intVal(shiftCount);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1400
	if (count >= 32) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1401
	    RETURN (__mkSmallInteger(0));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1402
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1403
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1404
	bits = __unsignedLongIntVal(self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1405
	if (count > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1406
	    bits = bits << count;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1407
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1408
	    bits = bits >> (-count);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1409
	}
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1410
#if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1411
	bits &= 0xFFFFFFFFL;
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1412
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1413
	RETURN (__MKUINT(bits));
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1414
    }
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1415
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1416
    ^ self primitiveFailed
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
     128 bitShift:24
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1420
     128 bitShift32:24
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1421
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1422
     1 bitShift:31
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1423
     1 bitShift32:31
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
!
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1426
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1427
bitXor32:aNumber
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1428
    "return the xor of the receiver and the argument.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1429
     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
  1430
     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
  1431
     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
  1432
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1433
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1434
    INT rslt;
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
    rslt =  __unsignedLongIntVal(self) ^ __unsignedLongIntVal(aNumber);
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1437
#if __POINTER_SIZE__ == 8
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1438
    rslt &= 0xFFFFFFFFL;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1439
#endif
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1440
    RETURN ( __MKUINT(rslt));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1441
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1442
    self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1443
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1444
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1445
     16r7FFFFFFF bitXor: 16r80000000          4294967295
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1446
     16r7FFFFFFF bitXor32: 16r80000000
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1447
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1448
! !
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1449
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1450
!LargeInteger methodsFor:'byte access'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1451
13992
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1452
byteSwapped
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1453
    "lsb -> msb;
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1454
     i.e. a.b ... y.z -> z.y. ... b.a"
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
    ^ self class digitBytes:digitByteArray MSB:true
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1457
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1458
    "
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1459
     (LargeInteger value:16r11223344) byteSwapped hexPrintString
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1460
     (LargeInteger value:16r44332211) byteSwapped hexPrintString
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1461
     16r88776655 byteSwapped hexPrintString
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1462
     16r11223344 byteSwapped hexPrintString
13992
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1463
    "
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1464
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1465
    "Created: / 31-01-2012 / 11:07:42 / cg"
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1466
!
459aea99d16b added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13371
diff changeset
  1467
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1468
byteSwapped32
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1469
    "byte swap a 32bit value; lsb -> msb;
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1470
     i.e. a.b.c.d -> d.c.b.a
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1471
     Useful for communication protocols"
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1472
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1473
%{
15909
9ffe9886b91b class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15908
diff changeset
  1474
    unsigned INT swapped;
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
    swapped = ( (__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[0]) << 24)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1477
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[1]) << 16)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1478
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[2]) << 8)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1479
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[3]));
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1480
    RETURN (__MKUINT(swapped));
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1481
%}.
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1482
    ^ super byteSwapped32
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1483
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1484
    "
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1485
     (LargeInteger value:16r11223344) byteSwapped32 hexPrintString
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1486
     (LargeInteger value:16r44332211) byteSwapped32 hexPrintString
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1487
     16r88776655 byteSwapped32 hexPrintString
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1488
     16r11223344 byteSwapped32 hexPrintString
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1489
    "
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
    "Created: / 31-01-2012 / 11:07:42 / cg"
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1492
!
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1493
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1494
byteSwapped64
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1495
    "byte swap a 64bit value; lsb -> msb;
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1496
     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
  1497
     Useful for communication protocols"
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1498
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1499
%{
15909
9ffe9886b91b class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15908
diff changeset
  1500
    unsigned INT swappedLO = 0;
9ffe9886b91b class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15908
diff changeset
  1501
    unsigned INT swappedHI;
9ffe9886b91b class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15908
diff changeset
  1502
    unsigned INT swapped;
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1503
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1504
    swappedHI = ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[0]) << 24)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1505
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[1]) << 16)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1506
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[2]) << 8)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1507
	      | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[3]));
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1508
    if (__byteArraySize(__INST(digitByteArray)) > 4) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1509
	swappedLO = ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[4]) << 24)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1510
		  | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[5]) << 16)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1511
		  | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[6]) << 8)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1512
		  | ((__ByteArrayInstPtr(__INST(digitByteArray))->ba_element[7]));
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1513
    }
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1514
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1515
#if __POINTER_SIZE__ == 8
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1516
    swapped = (swappedHI<<32) | swappedLO;
16520
a1a1d558cfa3 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 16124
diff changeset
  1517
    RETURN(__MKUINT( swapped ));
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1518
#else
16520
a1a1d558cfa3 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 16124
diff changeset
  1519
    RETURN(__MKLARGEINT64(1, swappedLO, swappedHI));
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1520
#endif
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1521
%}.
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  1522
    ^ super byteSwapped64
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
    "
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1525
     (LargeInteger value:16r11223344) byteSwapped64 hexPrintString
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1526
     (LargeInteger value:16r44332211) byteSwapped64 hexPrintString
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1527
     (LargeInteger value:16r1122334455667788) byteSwapped64 hexPrintString
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1528
     (LargeInteger value:16r8877665544332211) byteSwapped64 hexPrintString
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1529
     16r88776655 byteSwapped hexPrintString
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  1530
     16r11223344 byteSwapped hexPrintString
15908
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1531
    "
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1532
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1533
    "Created: / 31-01-2012 / 11:07:42 / cg"
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1534
!
35c0bb53fba1 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15838
diff changeset
  1535
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1536
digitAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1537
    "return 8 bits of value, starting at byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1538
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1539
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  1540
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1541
    return context._RETURN( ((STLargeInteger)self).digitAt( index.intValue() ) );
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1542
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1543
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1544
    index > digitByteArray size ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1545
    ^ digitByteArray at:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1546
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1547
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1548
digitAt:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1549
    "set the 8 bits, index is a byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1550
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1551
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  1552
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1553
    ERROR("cannot modify the digits of a LargeInteger");
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1554
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1555
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1556
    digitByteArray at:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1557
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1558
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1559
digitByteAt:index
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1560
    "return 8 bits of my signed value, starting at byte index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1561
     For positive receivers, this is the same as #digitAt:;
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1562
     for negative ones, the actual bit representation is returned."
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1563
18900
ace3f7e03da3 #DOCUMENTATION
Stefan Vogel <sv@exept.de>
parents: 18899
diff changeset
  1564
    |digits|
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1565
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1566
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  1567
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1568
    return context._RETURN( ((STLargeInteger)self).digitByteAt( index.intValue() ) );
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1569
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1570
%}.
6359
fcb206734265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6106
diff changeset
  1571
    sign >= 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1572
	index > digitByteArray size ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1573
	    ^ 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1574
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1575
	^ digitByteArray at:index.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1576
    ].
6359
fcb206734265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6106
diff changeset
  1577
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1578
    "/ negative int - do 2's complement here
18900
ace3f7e03da3 #DOCUMENTATION
Stefan Vogel <sv@exept.de>
parents: 18899
diff changeset
  1579
    digits := (self bitInvert + 1) digitBytes.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1580
    index > digits size ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1581
	^ 16rFF
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
    ^ digits at:index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1584
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
     16r11111111111111111111 negated digitByteAt:1
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1587
     0 asLargeInteger digitByteAt:1
18900
ace3f7e03da3 #DOCUMENTATION
Stefan Vogel <sv@exept.de>
parents: 18899
diff changeset
  1588
     -1 asLargeInteger digitByteAt:1
ace3f7e03da3 #DOCUMENTATION
Stefan Vogel <sv@exept.de>
parents: 18899
diff changeset
  1589
     -1 digitByteAt:1
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1590
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1591
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1592
    "Created: / 25.10.1998 / 14:12:21 / cg"
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1593
!
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1594
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1595
digitBytes
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  1596
    "return a byteArray filled with the receiver's bits
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1597
     (8 bits of the absolute value per element).
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1598
     Least significant byte is first!!"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1599
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1600
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  1601
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1602
    return context._RETURN( ((STLargeInteger)self).digitBytes() );
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1603
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1604
%}.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1605
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1606
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1607
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1608
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1609
15569
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1610
digitBytesMSB
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  1611
    "return a byteArray filled with the receiver's bits
15569
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1612
     (8 bits of the absolute value per element),
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1613
     most significant byte first"
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1614
22101
bf59a1a919c7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21986
diff changeset
  1615
     ^ digitByteArray reversed.
bf59a1a919c7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21986
diff changeset
  1616
bf59a1a919c7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21986
diff changeset
  1617
    "Modified: / 25-07-2017 / 17:02:31 / stefan"
15569
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1618
!
8a82c6a65677 new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15326
diff changeset
  1619
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1620
digitBytesMSB:msbFlag
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  1621
    "return a byteArray filled with the receiver's bits
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1622
     (8 bits of the absolute value per element),
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1623
     if msbflag = true, most significant byte is first,
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1624
     otherwise least significant byte is first"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1625
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1626
    msbFlag ifTrue:[
22101
bf59a1a919c7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21986
diff changeset
  1627
        ^ digitByteArray reversed.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1628
    ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1629
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1630
22101
bf59a1a919c7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21986
diff changeset
  1631
    "Modified: / 25-07-2017 / 17:02:51 / stefan"
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1632
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1633
18899
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1634
digitBytesSigned
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1635
    "return a byteArray filled with the receiver's bits
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1636
     (8 bits of the value (which may be negative) per element).
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1637
     Least significant byte is first!!"
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1638
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1639
    sign > 0 ifTrue:[
22267
77906926cbae #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22101
diff changeset
  1640
        ^ digitByteArray
18899
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1641
    ].
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1642
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1643
    "answer the 2's complement"
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1644
    ^ (self bitInvert + 1) digitBytes.
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1645
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1646
    "
22267
77906926cbae #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22101
diff changeset
  1647
        16r12345678901234567890 digitBytesSigned
77906926cbae #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22101
diff changeset
  1648
        16r-12345678901234567890 digitBytesSigned
18899
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1649
    "
22267
77906926cbae #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22101
diff changeset
  1650
77906926cbae #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22101
diff changeset
  1651
    "Modified (comment): / 19-09-2017 / 16:33:19 / stefan"
18899
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1652
!
df3418f55649 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18855
diff changeset
  1653
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1654
digitLength
19320
bf817fb15805 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19262
diff changeset
  1655
    "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
  1656
     For negative receivers, the result is not defined by the language standard.
bf817fb15805 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19262
diff changeset
  1657
     ST/X returns the digitLength of its absolute value."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1658
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1659
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1660
     check if there is a 0-byte ...
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1661
     this allows to ask unnormalized LargeIntegers
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1662
     for their digitLength
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1663
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1664
    |l "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1665
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1666
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  1667
#ifdef __SCHTEAM__
18709
Claus Gittinger <cg@exept.de>
parents: 18621
diff changeset
  1668
    return context._RETURN( STInteger._new( ((STLargeInteger)self).digitLength() ));
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1669
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  1670
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1671
    l := digitByteArray size.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1672
    [l ~~ 0 and:[(digitByteArray at:l) == 0]] whileTrue:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  1673
	l := l - 1.
701
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
    ^ l
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1676
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1677
    "Modified: 31.7.1997 / 13:18:28 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1678
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1679
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1680
digits
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1681
    "obsolete, use #digitBytes"
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1682
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1683
    <resource:#obsolete>
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1684
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1685
    ^ digitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1686
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1687
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1688
!LargeInteger methodsFor:'coercing & converting'!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1689
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1690
asLargeInteger
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  1691
    "return a LargeInteger with same value as myself - that's me"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1692
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1693
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1694
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1695
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1696
asSigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1697
    "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
  1698
     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
  1699
     convert C/Java numbers."
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
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1702
    int rslt;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1703
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1704
    rslt =  (int)(__unsignedLongIntVal(self));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1705
    RETURN ( __MKINT(rslt));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1706
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1707
    self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1708
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1709
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1710
     16r80000000 asSigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1711
     16r40000000 asSigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1712
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1713
!
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1714
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1715
asSmallInteger
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1716
    "return a SmallInteger with same value as myself -
18845
ee0ed4f54c44 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18709
diff changeset
  1717
     the result is invalid if the receiver's value cannot
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1718
     be represented as a SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1719
     Q: should we raise an exception if this happens ?"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1720
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1721
    |value|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1722
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1723
    value := 0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1724
    (sign == 0) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1725
	digitByteArray reverseDo:[:aDigit |
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1726
	    value := (value times:256) + aDigit
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1727
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1728
	(sign < 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1729
	    value := value negated
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1730
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1731
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1732
    ^ value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1733
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1734
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1735
asUnsigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1736
    "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
  1737
     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
  1738
     convert C/Java numbers."
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
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1741
    unsigned int rslt;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1742
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1743
    rslt =  (int)(__unsignedLongIntVal(self));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1744
    RETURN ( __MKUINT(rslt));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1745
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1746
    self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1747
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1748
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1749
     16r80000000 asUnsigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1750
     16r40000000 asUnsigned32
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1751
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1752
!
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  1753
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1754
coerce:aNumber
18845
ee0ed4f54c44 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18709
diff changeset
  1755
    "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
  1756
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1757
    ^ aNumber asLargeInteger
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
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1760
compressed
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1761
    "if the receiver can be represented as a SmallInteger, return
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1762
     a SmallInteger with my value;
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1763
     otherwise remove leading zero bytes in the digitByte array
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1764
     and return the receiver"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1765
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1766
    |index "{ Class: SmallInteger }"
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1767
     val   "{ Class: SmallInteger }"
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1768
     index0
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1769
    |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1770
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1771
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1772
    OBJ t;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1773
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1774
    if (__INST(sign) == __mkSmallInteger(0)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1775
	RETURN (__mkSmallInteger(0));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1776
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1777
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1778
    t = __INST(digitByteArray);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1779
    if (__isByteArray(t)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1780
	unsigned char *__digitBytes = __ByteArrayInstPtr(t)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1781
	int _idx, _idx0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1782
	INT _val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1783
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1784
	_idx = _idx0 = __byteArraySize(t);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1785
	while ((_idx > 0) && (__digitBytes[_idx - 1] == 0)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1786
	    _idx--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1787
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  1788
#if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1789
	switch (_idx) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1790
	    case 8:
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1791
		_val = __digitBytes[7];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1792
		if (_val <= 0x40) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1793
		    _val = (_val<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1794
		    _val = (_val + __digitBytes[6]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1795
		    _val = (_val + __digitBytes[5]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1796
		    _val = (_val + __digitBytes[4]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1797
		    _val = (_val + __digitBytes[3]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1798
		    _val = (_val + __digitBytes[2]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1799
		    _val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1800
		    _val += __digitBytes[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1801
		    if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1802
			_val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1803
		    if (__ISVALIDINTEGER(_val)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1804
			RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1805
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1806
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1807
		break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1808
	    case 7:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1809
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1810
		_val = ((INT *)__digitBytes)[0] & 0x00FFFFFFFFFFFFFFL;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1811
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1812
		_val = (__digitBytes[6]<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1813
		_val = (_val + __digitBytes[5]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1814
		_val = (_val + __digitBytes[4]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1815
		_val = (_val + __digitBytes[3]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1816
		_val = (_val + __digitBytes[2]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1817
		_val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1818
		_val += __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1819
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1820
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1821
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1822
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1823
	    case 6:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1824
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1825
		_val = ((INT *)__digitBytes)[0] & 0x0000FFFFFFFFFFFFL;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1826
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1827
		_val = (__digitBytes[5]<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1828
		_val = (_val + __digitBytes[4]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1829
		_val = (_val + __digitBytes[3]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1830
		_val = (_val + __digitBytes[2]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1831
		_val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1832
		_val += __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1833
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1834
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1835
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1836
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1837
	    case 5:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1838
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1839
		_val = ((INT *)__digitBytes)[0] & 0x000000FFFFFFFFFFL;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1840
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1841
		_val = (__digitBytes[4]<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1842
		_val = (_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 4:
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] & 0x00000000FFFFFFFFL;
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[3]<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1855
		_val = (_val + __digitBytes[2]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1856
		_val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1857
		_val += __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1858
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1859
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1860
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1861
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1862
	    case 3:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1863
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1864
		_val = ((int *)__digitBytes)[0] & 0x00FFFFFF;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1865
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1866
		_val = (__digitBytes[2]<<8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1867
		_val = (_val + __digitBytes[1]) << 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1868
		_val += __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1869
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1870
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1871
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1872
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1873
	    case 2:
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1874
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1875
		_val = ((int *)__digitBytes)[0] & 0x0000FFFF;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1876
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1877
		_val = (__digitBytes[1]<<8) + __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1878
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1879
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1880
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1881
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1882
	    case 1:
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1883
		_val = __digitBytes[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1884
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1885
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1886
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1887
	    case 0:
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1888
		RETURN (__mkSmallInteger(0));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1889
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1890
	}
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1891
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1892
	if (_idx <= 4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1893
	    if (_idx <= 2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1894
		if (_idx == 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1895
		    RETURN (__mkSmallInteger(0));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1896
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1897
		if (_idx == 1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1898
		    _val = __digitBytes[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1899
		    if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1900
			_val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1901
		    RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1902
		}
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1903
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1904
		_val = ((int *)__digitBytes)[0] & 0x0000FFFF;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1905
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1906
		_val = (__digitBytes[1]<<8) + __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1907
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1908
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1909
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1910
		RETURN (__mkSmallInteger(_val));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1911
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1912
	    if (_idx == 3) {
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1913
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1914
		_val = ((int *)__digitBytes)[0] & 0x00FFFFFF;
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1915
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1916
		_val = (((__digitBytes[2]<<8) + __digitBytes[1])<<8) + __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1917
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1918
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1919
		    _val = -_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
	    _val = __digitBytes[3];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1923
	    if (_val <= 0x40) {
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1924
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1925
		_val = ((int *)__digitBytes)[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1926
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1927
		_val = (((((_val<<8) + __digitBytes[2])<<8) + __digitBytes[1])<<8) + __digitBytes[0];
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  1928
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1929
		if (__INST(sign) == __mkSmallInteger(-1))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1930
		    _val = -_val;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1931
		if (__ISVALIDINTEGER(_val)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1932
		    RETURN (__mkSmallInteger(_val));
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
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1935
	}
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1936
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1937
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1938
	if (_idx == _idx0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1939
	    RETURN (self);
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
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1942
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1943
	 * must copy & cut off some (zero)bytes
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1944
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1945
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1946
	    OBJ newDigits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1947
	    OBJ oldDigits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1948
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1949
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1950
	     * careful - there is no context here to protect
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1951
	     * the receiver ...
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
	    __PROTECT__(self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1954
	    __PROTECT__(__INST(digitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1955
	    newDigits = __BYTEARRAY_UNINITIALIZED_NEW_INT(_idx);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1956
	    __UNPROTECT__(oldDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1957
	    __UNPROTECT__(self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1958
	    if (newDigits) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1959
		bcopy(__ByteArrayInstPtr(oldDigits)->ba_element,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1960
		      __ByteArrayInstPtr(newDigits)->ba_element,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1961
		      _idx);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1962
		__INST(digitByteArray) = newDigits; __STORE(self, newDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1963
		RETURN (self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1964
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1965
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1966
	     * allocation failed ...
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1967
	     * ... fall through to trigger the error
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1968
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1969
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1970
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1971
%}.
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1972
    index0 := index := digitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1973
    [(index > 0) and:[(digitByteArray at:index) == 0]] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1974
	index := index - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1975
    ].
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1976
"/    ((index < SmallInteger maxBytes)
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1977
"/    or:[(index == SmallInteger maxBytes)
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1978
"/            and:[(digitByteArray at:index) < 16r20]])
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1979
"/    ifTrue:[
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1980
"/        val := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1981
"/        1 to:index do:[:i |
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1982
"/            val := val bitShift:8.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1983
"/            val := val bitOr:(digitByteArray at:i).
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1984
"/        ].
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1985
"/        ^ val * sign
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1986
"/    ].
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1987
    (index ~~ index0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  1988
	digitByteArray := digitByteArray copyFrom:1 to:index
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1989
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1990
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1991
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1992
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1993
generality
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1994
    "return the generality value - see ArithmeticValue>>retry:coercing:"
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1995
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1996
    ^ 40
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1997
!
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1998
16124
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  1999
nilAllInstvars
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  2000
    digitByteArray nilAllInstvars.
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  2001
    digitByteArray := sign := nil.
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  2002
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  2003
    "
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  2004
      100 factorial nilAllInstvars
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  2005
    "
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  2006
!
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  2007
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2008
value:aSmallInteger
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  2009
    "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
  2010
     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
  2011
     This should only be used internally,
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  2012
     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
  2013
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2014
    |absValue
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2015
     b1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2016
     b2 "{ Class: SmallInteger }"
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2017
     b3 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2018
     b4 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2019
     b5 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2020
     b6 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2021
     b7 "{ Class: SmallInteger }"|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2022
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2023
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2024
     could have simply created a 4-byte largeinteger and normalize it.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  2025
     The code below does the normalize right away, avoiding the
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2026
     overhead of producing any intermediate byte-arrays (and the scanning)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2027
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2028
    (aSmallInteger == 0) ifTrue: [
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2029
	digitByteArray := ByteArray with:0.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2030
	sign := 0.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2031
	^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2032
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  2033
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2034
    (aSmallInteger < 0) ifTrue: [
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2035
	sign := -1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2036
	absValue := aSmallInteger negated
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2037
    ] ifFalse: [
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2038
	sign := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2039
	absValue := aSmallInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2040
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  2041
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2042
    b1 := absValue bitAnd:16rFF.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2043
    absValue := absValue bitShift:-8.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2044
    absValue == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2045
	digitByteArray := ByteArray with:b1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2046
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2047
	b2 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2048
	absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2049
	absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2050
	    digitByteArray := ByteArray with:b1 with:b2
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2051
	] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2052
	    b3 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2053
	    absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2054
	    absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2055
		digitByteArray := ByteArray with:b1 with:b2 with:b3
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2056
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2057
		b4 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2058
		absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2059
		absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2060
		    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2061
		] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2062
		    b5 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2063
		    absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2064
		    absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2065
			digitByteArray := ByteArray new:5.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2066
			digitByteArray at:1 put:b1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2067
			digitByteArray at:2 put:b2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2068
			digitByteArray at:3 put:b3.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2069
			digitByteArray at:4 put:b4.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2070
			digitByteArray at:5 put:b5.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2071
		    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2072
			b6 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2073
			absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2074
			absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2075
			    digitByteArray := ByteArray new:6.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2076
			    digitByteArray at:1 put:b1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2077
			    digitByteArray at:2 put:b2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2078
			    digitByteArray at:3 put:b3.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2079
			    digitByteArray at:4 put:b4.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2080
			    digitByteArray at:5 put:b5.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2081
			    digitByteArray at:6 put:b6.
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
			    b7 := absValue bitAnd:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2084
			    absValue := absValue bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2085
			    absValue == 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2086
				digitByteArray := ByteArray new:7.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2087
				digitByteArray at:1 put:b1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2088
				digitByteArray at:2 put:b2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2089
				digitByteArray at:3 put:b3.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2090
				digitByteArray at:4 put:b4.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2091
				digitByteArray at:5 put:b5.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2092
				digitByteArray at:6 put:b6.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2093
				digitByteArray at:7 put:b7.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2094
			    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2095
				digitByteArray := ByteArray new:8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2096
				digitByteArray at:1 put:b1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2097
				digitByteArray at:2 put:b2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2098
				digitByteArray at:3 put:b3.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2099
				digitByteArray at:4 put:b4.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2100
				digitByteArray at:5 put:b5.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2101
				digitByteArray at:6 put:b6.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2102
				digitByteArray at:7 put:b7.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2103
				digitByteArray at:8 put:absValue.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2104
			    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2105
			]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2106
		    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2107
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2108
	    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2109
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2110
    ]
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2111
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2112
    "Modified: / 26.5.1999 / 22:18:14 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2113
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2114
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2115
!LargeInteger methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2116
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2117
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2118
    "return true, if the argument, aNumber is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2119
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2120
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2121
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2122
    (aNumber class == self class) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2123
	otherSign := aNumber sign.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2124
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2125
	(sign > 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2126
	    "I am positive"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2127
	    (otherSign > 0) ifTrue:[^ self absLess:aNumber].
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
	"I am negative"
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
	(otherSign == 0) ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2133
	^ (aNumber absLess:self)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2134
    ].
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2135
    (aNumber class == SmallInteger) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2136
	otherSign := aNumber sign.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2137
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2138
	(sign > 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2139
	    "I am positive"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2140
	    ^ false "aNumber is <= 0"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2141
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2142
	(sign == 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2143
	    (otherSign > 0) ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2144
	    ^ false
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2145
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2146
	"I am negative"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2147
	^ true
14766
ae12897bef55 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 13992
diff changeset
  2148
    ].
ae12897bef55 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 13992
diff changeset
  2149
    "/ hack for epsilon tests
ae12897bef55 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 13992
diff changeset
  2150
    (aNumber class == Float) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2151
	self negative ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2152
	    "/ 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
  2153
	    aNumber >= SmallInteger minVal asFloat ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2154
	] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2155
	    "/ 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
  2156
	    aNumber <= SmallInteger maxVal asFloat ifTrue:[^ false].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2157
	].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2158
    ].
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2159
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2160
    ^ aNumber lessFromInteger:self
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  2161
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  2162
    "Modified: / 31.7.2002 / 10:08:19 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2163
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2164
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2165
= aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  2166
    "return true, if the argument represents the same numeric value
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  2167
     as the receiver, false otherwise"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2168
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2169
    "/ speed up compare to 0
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2170
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  2171
    (aNumber == 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2172
	^ sign == 0
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2173
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2174
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2175
    (aNumber class == self class) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2176
	"/
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2177
	"/ here, we depend on the fact, that largeinteger
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2178
	"/ results are always converted to smallInts, if possible.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2179
	"/ therefore, a largeInt in the smallInt range is not allowed (possible)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2180
	"/
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2181
	aNumber class == SmallInteger ifTrue:[^ false ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2182
	^ aNumber equalFromInteger:self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2183
    ].
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  2184
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2185
    (aNumber sign == sign) ifFalse:[^ false].
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2186
    ^ 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
  2187
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2188
    "Modified: / 13.2.1998 / 11:43:15 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2189
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2190
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2191
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2192
    "return true, if the argument, aNumber is less than the receiver"
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
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2195
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2196
    (aNumber class == self class) ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2197
	^ (aNumber < self)
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
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2200
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2201
    (sign > 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2202
	"I am positive"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2203
	(otherSign > 0) ifTrue:[^ aNumber absLess:self].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2204
	^ true "aNumber is <= 0"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2205
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2206
    (sign == 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2207
	"I am zero"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2208
	(otherSign > 0) ifTrue:[^ false].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2209
	^ true
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2210
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2211
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2212
    (otherSign > 0) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2213
    (otherSign == 0) ifTrue:[^ false].
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  2214
    ^ (self absLess:aNumber)
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  2215
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  2216
    "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
  2217
!
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  2218
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  2219
hash
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  2220
    "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
  2221
19555
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2222
    |sz h|
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2223
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2224
    sz := digitByteArray size.
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2225
    (sz <= SmallInteger maxBytes and:[self absLess:SmallInteger maxVal]) ifTrue:[
22380
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2226
        "I am really an unnormalized SmallInteger, answer the same hash as for the SmallInteger"
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2227
        ^ self bitAnd:SmallInteger maxVal.
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2228
    ].
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
    h := digitByteArray computeXorHashFrom:1 to:8.                  "/ the low 8 bytes
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2231
    sz > 8 ifTrue:[                                                 "/ the high 8 bytes
22380
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2232
        "/ the code below is actually not doing what was intended 
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2233
        "/ (to take the hashes of the last 8 bytes)
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2234
        "/ It does actually take the last 9 bytes (due to a mistake of the original programmer...)
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2235
        "/ However, we will not change it, but keep it that way, in case the hashvalue already found
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2236
        "/ its way into some dictionary (as key-index).
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2237
        "/ It does not really hurt anyway, so there is no need to change it.
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2238
        h := h bitXor:(digitByteArray computeXorHashFrom:sz-8 to:sz).
19555
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2239
    ].
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2240
    ^ h
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2241
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2242
    "
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  2243
     16r80000000 hash
19555
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2244
     16r-80000000 asLargeInteger hash
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  2245
     16r80000008 hash
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  2246
     16r8000000000008 hash
19555
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2247
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2248
     16r8000000000000000 hash
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2249
     16r8000000000000008 hash
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2250
     16r800000000000000000008 hash
29a4c770f926 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19320
diff changeset
  2251
     16r-800000000000000000008 hash
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2252
    "
22380
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2253
f21fb6440a1d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22370
diff changeset
  2254
    "Modified (format): / 28-11-2017 / 15:04:59 / cg"
17246
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2255
!
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2256
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2257
hashMultiply
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2258
    "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
  2259
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2260
    "Truncate to 28 bits and try again"
0e609e06e051 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 17128
diff changeset
  2261
    ^(self bitAnd: 16rFFFFFFF) hashMultiply
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2262
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2263
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2264
!LargeInteger methodsFor:'double dispatching'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2265
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2266
differenceFromInteger:anInteger
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2267
    "sent, when anInteger does not know how to subtract the receiver.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2268
     Return the result of 'anInteger - self'. The argument must be a SmallInteger."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2269
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2270
    anInteger > 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2271
	sign > 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2272
	    ^ self absFastMinus:anInteger sign:-1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2273
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2274
	^ self absFastPlus:anInteger sign:1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2275
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2276
    anInteger == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2277
	^ self negated
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
    sign > 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2280
	^ self absFastPlus:anInteger negated sign:-1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2281
    ].
10728
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2282
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2283
    self > anInteger ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2284
	^ self absFastMinus:anInteger asLargeInteger sign:-1
10728
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2285
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2286
	^ anInteger asLargeInteger absFastMinus:self sign:-1
10728
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2287
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2288
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2289
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2290
     12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2291
     -12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2292
     12345678901234567890 differenceFromInteger:0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2293
     12345678901234567890 differenceFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2294
     12345678901234567890 differenceFromInteger:-1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2295
     -12345678901234567890 differenceFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2296
     -12345678901234567890 differenceFromInteger:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2297
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2298
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2299
    "Modified: 20.10.1996 / 18:41:54 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2300
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2301
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2302
equalFromInteger:anInteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2303
    "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
  2304
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  2305
    |otherClass|
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2306
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2307
    "/
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2308
    "/ here, we depend on the fact, that largeinteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2309
    "/ results are always converted to smallInts, if possible.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2310
    "/ therefore, a largeInt in the smallInt range is not allowed (possible)
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2311
    "/
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  2312
    otherClass := anInteger class.
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  2313
    otherClass == SmallInteger ifTrue:[^ false ].
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  2314
    otherClass == self class ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2315
	(anInteger sign == sign) ifFalse:[^ false].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2316
	^ self absEq:anInteger
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2317
    ].
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  2318
    ^ super equalFromInteger:anInteger
11507
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
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2321
lessFromInteger:anInteger
18855
85ed6541937d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18848
diff changeset
  2322
    "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
  2323
     Return true if anInteger < self"
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2324
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2325
    "/
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2326
    "/ here, we depend on the fact, that largeinteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2327
    "/ results are always converted to smallInts, if possible.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2328
    "/ therefore, a largeInt in the smallInt range is not allowed (possible)
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2329
    "/
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2330
    (anInteger class == SmallInteger) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2331
	(sign > 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2332
	    "I am positive - any largeInteger is larger than any smallInteger"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2333
	    ^ true "anInteger is <= 0"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2334
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2335
	"I am negative - any negative largeInteger is smaller than any smallInteger"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2336
	^ false
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2337
    ].
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2338
    ^ super lessFromInteger:anInteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2339
!
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2340
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2341
productFromInteger:anInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2342
    "sent, when anInteger does not know how to multiply the receiver.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2343
     Return the product of the receiver and the argument, aSmallInteger"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2344
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2345
    |num result
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2346
     resultDigitByteArray
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2347
     val     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2348
     len     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2349
     carry   "{ Class: SmallInteger }"
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2350
     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
  2351
     ok lResult|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2352
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2353
    "multiplying by a small integer is done here"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2354
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2355
    "trivial cases"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2356
    anInteger == 0 ifTrue:[^ 0].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2357
    anInteger == 1 ifTrue:[^ self].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2358
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2359
    num := anInteger abs.
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  2360
    SmallInteger maxBytes == 8 ifTrue:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2361
	(num > 16rFFFFFFFFFF) ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2362
	    "if num is too big (so that multiplying by a byte could create a Large)"
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2363
	    ^ anInteger retry:#* coercing:self
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2364
	].
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2365
    ] ifFalse:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2366
	(num > 16r3FFFFF) ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2367
	    "if num is too big (so that multiplying by a byte could create a Large)"
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2368
	    ^ anInteger retry:#* coercing:self
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2369
	].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2370
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2371
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2372
    len := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2373
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2374
    val := num.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  2375
    val <= 16rFF ifTrue:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2376
	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
  2377
    ] ifFalse:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2378
	val <= 16rFFFF ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2379
	    lResult := len + 2
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2380
	] ifFalse:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2381
	    val <= 16rFFFFFF ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2382
		lResult := len + 4.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2383
	    ] ifFalse:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2384
		val <= 16rFFFFFFFF ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2385
		    lResult := len + 6.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2386
		] ifFalse:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2387
		    val <= 16rFFFFFFFFFF ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2388
			lResult := len + 8.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2389
		    ] ifFalse:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2390
			val <= 16rFFFFFFFFFF ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2391
			    lResult := len + 10.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2392
			] ifFalse:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2393
			    val <= 16rFFFFFFFFFFFF ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2394
				lResult := len + 12.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2395
			    ] ifFalse:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2396
				lResult := len + 14.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2397
			    ]
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2398
			]
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2399
		    ]
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2400
		]
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2401
	    ]
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2402
	]
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2403
    ].
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  2404
    resultDigitByteArray := ByteArray uninitializedNew:lResult.
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2855
diff changeset
  2405
    result := self class basicNew setDigits:resultDigitByteArray.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2406
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2407
    anInteger < 0 ifTrue:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2408
	sign > 0 ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2409
	    result setSign:-1
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2410
	].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2411
    ] ifFalse:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2412
	sign < 0 ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2413
	    result setSign:sign
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2414
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2415
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2416
85
claus
parents: 77
diff changeset
  2417
    ok := false.
claus
parents: 77
diff changeset
  2418
%{
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2419
    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
  2420
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2421
    if (__isSmallInteger(len)
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2422
     && __isByteArray(__digitByteArray)
85
claus
parents: 77
diff changeset
  2423
     && __isByteArray(resultDigitByteArray)) {
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2424
	INT _l = __intVal(len);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2425
	INT _v = __intVal(val);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2426
	unsigned INT _carry = 0;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2427
	unsigned INT _prod;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2428
	unsigned char *digitP = __ByteArrayInstPtr(__digitByteArray)->ba_element;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2429
	unsigned char *resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2430
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2431
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2432
	 * skipping zeros does not help much (a few percent) on
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2433
	 * a P5 or other CPUS with a fast multiplier.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2434
	 * It may make more of a difference on CPUs with slower 0-multiply.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2435
	 * Late news: it actually hurts modern x86_64 cpus.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2436
	 * So only reenable for specific CPUs after concrete benchmarks.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2437
	 */
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  2438
#if 0
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2439
	while ((_l >= sizeof(INT)) && (((unsigned INT *)digitP)[0] == 0)) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2440
	    ((unsigned INT *)resultP)[0] = 0;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2441
	    digitP += sizeof(INT);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2442
	    resultP += sizeof(INT);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2443
	    _l -= sizeof(INT);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2444
	}
19132
0c0046873268 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19126
diff changeset
  2445
#endif
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  2446
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2447
#if defined(__LSBFIRST__)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2448
# if defined (__GNUC__) && defined(__i386__) && (__POINTER_SIZE__ == 4)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2449
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2450
	 * can do it long-word-wise;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2451
	 * 32*32 -> 64 multiplication
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2452
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2453
	while (_l > 3) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2454
	    unsigned __pHi, __pLow;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2455
	    unsigned __digit;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2456
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2457
	    /*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2458
	     * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2459
	     * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2460
	     */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2461
	    __digit = ((unsigned long *)digitP)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2462
	    asm ("mull %3               \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2463
		  addl %4,%%eax         \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2464
		  adcl $0,%%edx"
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2465
		    : "=a"  (__pLow),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2466
		      "=d"  (__pHi)
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2467
		    : "0"   (__digit),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2468
		      "1"   (ASM_ULONGCAST(_v)),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2469
		      "rm"  (ASM_ULONGCAST(_carry)) );
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2470
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2471
	    ((unsigned long *)resultP)[0] = __pLow;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2472
	    _carry = __pHi;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2473
	    digitP += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2474
	    resultP += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2475
	    _l -= 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2476
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2477
# else /* not GNU-i386 */
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  2478
#  if defined(__win32__) && defined(__BORLANDC__) && defined(__x86__) && (__POINTER_SIZE__ == 4)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2479
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2480
	 * can do it long-word-wise;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2481
	 * 32*32 -> 64 multiplication
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2482
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2483
	while (_l > 3) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2484
	    unsigned __pLow;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2485
	    unsigned digit;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2486
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2487
	    /*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2488
	     * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2489
	     * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2490
	     */
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  2491
/*
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2492
	    digit = ((unsigned long *)digitP)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2493
	    edx::eax = (digit * _v);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2494
	    edx::eax += _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2495
	    ((unsigned long *)resultP)[0] = eax; -- pLow
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2496
	    _carry = edx; -- pHigh
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2497
	    digitP += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2498
	    resultP += 4;
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  2499
*/
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2500
	    digit = ((unsigned long *)digitP)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2501
	    asm {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2502
		mov   eax, digit
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2503
		mov   edx, _v
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2504
		mul   edx
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2505
		add   eax, _carry
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2506
		adc   edx, 0
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2507
		mov   __pLow, eax
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2508
		mov   _carry, edx
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2509
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2510
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2511
	    ((unsigned long *)resultP)[0] = __pLow;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2512
	    digitP += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2513
	    resultP += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2514
	    _l -= 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2515
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2516
#  else /* not WIN32-i386 */
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2517
#   if defined(INT128)
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2518
	if (_v <= 0xFFFFFFFFFFFFFFFFL) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2519
	    /* have 128bit ints; can do it int64-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2520
	     *
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2521
	     */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2522
	    while (_l >= 8) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2523
		UINT64 __t1;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2524
		UINT128 _prod128a;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2525
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2526
		__t1 = ((UINT64 *)digitP)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2527
		_prod128a = (INT128)_v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2528
		_prod128a *= __t1;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2529
		_prod128a += _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2530
		((UINT64 *)resultP)[0] = _prod128a;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2531
		_carry = _prod128a >> 64;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2532
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2533
		digitP += (8);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2534
		resultP += (8);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2535
		_l -= (8);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2536
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2537
	    while (_l >= 4) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2538
		unsigned __t;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2539
		UINT128 _prod128;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2540
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2541
		__t = ((unsigned *)digitP)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2542
		_prod128 = (INT128)_v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2543
		_prod128 *= __t;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2544
		_prod128 += _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2545
		((unsigned *)resultP)[0] = _prod128 /* & 0xFFFFFFFFL */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2546
		_carry = _prod128 >> 32;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2547
		digitP += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2548
		resultP += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2549
		_l -= 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2550
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2551
	    if (_l >= 2) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2552
		unsigned short __t;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2553
		UINT128 _prod128;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2554
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2555
		__t = ((unsigned short *)digitP)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2556
		_prod128 = (INT128)_v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2557
		_prod128 *= __t;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2558
		_prod128 += _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2559
		((unsigned short *)resultP)[0] = _prod128 /* & 0xFFFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2560
		_carry = _prod128 >> 16;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2561
		digitP += 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2562
		resultP += 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2563
		_l -= 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2564
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2565
	    if (_l > 0) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2566
		UINT128 _prod128;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2567
		_prod128 = *digitP++ * _v + _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2568
		*resultP++ = _prod128 /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2569
		_carry = _prod128 >> 8;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2570
		_l--;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2571
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2572
	}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2573
#   endif
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2574
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2575
#   if defined(INT64)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2576
	if (_v <= 0xFFFFFFFFL) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2577
	    /* have 64bit ints; can do it int-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2578
	     *
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2579
	     * max: 0xFFFFFFFF * 0xFFFFFFFF -> 0xFFFFFFFE.0001
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2580
	     * + maxCarry (0xFFFFFFFF)  -> 0xFFFFFFFF.0000
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2581
	     */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2582
	    while (_l >= (4+4+4+4)) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2583
		unsigned __t1, __t2, __t3, __t4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2584
		UINT64 _prod64a, _prod64b, _prod64c, _prod64d;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2585
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2586
		__t1 = ((unsigned *)digitP)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2587
		_prod64a = (INT64)_v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2588
		_prod64a *= __t1;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2589
		_prod64a += _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2590
		((unsigned *)resultP)[0] = _prod64a /* & 0xFFFFFFFFL */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2591
		_carry = _prod64a >> 32;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2592
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2593
		__t2 = ((unsigned *)digitP)[1];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2594
		_prod64b = (INT64)_v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2595
		_prod64b *= __t2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2596
		_prod64b += _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2597
		((unsigned *)resultP)[1] = _prod64b /* & 0xFFFFFFFFL */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2598
		_carry = _prod64b >> 32;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2599
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2600
		__t3 = ((unsigned *)digitP)[2];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2601
		_prod64c = (INT64)_v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2602
		_prod64c *= __t3;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2603
		_prod64c += _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2604
		((unsigned *)resultP)[2] = _prod64c /* & 0xFFFFFFFFL */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2605
		_carry = _prod64c >> 32;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2606
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2607
		__t4 = ((unsigned *)digitP)[3];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2608
		_prod64d = (INT64)_v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2609
		_prod64d *= __t4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2610
		_prod64d += _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2611
		((unsigned *)resultP)[3] = _prod64d /* & 0xFFFFFFFFL */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2612
		_carry = _prod64d >> 32;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2613
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2614
		digitP += (4+4+4+4);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2615
		resultP += (4+4+4+4);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2616
		_l -= (4+4+4+4);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2617
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2618
	    while (_l >= 4) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2619
		unsigned __t;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2620
		UINT64 _prod64;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2621
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2622
		__t = ((unsigned *)digitP)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2623
		_prod64 = (INT64)_v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2624
		_prod64 *= __t;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2625
		_prod64 += _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2626
		((unsigned *)resultP)[0] = _prod64 /* & 0xFFFFFFFFL */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2627
		_carry = _prod64 >> 32;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2628
		digitP += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2629
		resultP += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2630
		_l -= 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2631
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2632
	    if (_l >= 2) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2633
		unsigned short __t;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2634
		UINT64 _prod64;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2635
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2636
		__t = ((unsigned short *)digitP)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2637
		_prod64 = (INT64)_v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2638
		_prod64 *= __t;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2639
		_prod64 += _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2640
		((unsigned short *)resultP)[0] = _prod64 /* & 0xFFFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2641
		_carry = _prod64 >> 16;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2642
		digitP += 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2643
		resultP += 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2644
		_l -= 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2645
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2646
	    if (_l > 0) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2647
		UINT64 _prod64;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2648
		_prod64 = *digitP++ * _v + _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2649
		*resultP++ = _prod64 /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2650
		_carry = _prod64 >> 8;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2651
		_l--;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2652
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2653
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2654
#   else /* no INT64 type */
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2655
	if (_v <= 0xFFFF) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2656
	    /* can do it short-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2657
	     *
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2658
	     * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2659
	     * + maxCarry (0xFFFF)  -> 0xFFFF.0000
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2660
	     */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2661
	    while (_l > 1) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2662
		_prod = ((unsigned short *)digitP)[0] * _v + _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2663
		((unsigned short *)resultP)[0] = _prod /* & 0xFFFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2664
		_carry = _prod >> 16;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2665
		digitP += 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2666
		resultP += 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2667
		_l -= 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2668
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2669
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2670
#   endif /* no INT64 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2671
#  endif /* not WIN32-i386 */
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  2672
# endif /* not GNU-i386 */
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  2673
#else /* not LSB_FIRST */
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2674
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2675
# ifdef __mips__
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2676
#  define LOAD_WORD_WISE
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2677
   /* 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
  2678
# endif
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2679
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2680
	if (_v <= 0xFFFF) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2681
	    /* can do it short-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2682
	     *
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2683
	     * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2684
	     * + maxCarry (0xFFFF)  -> 0xFFFF.0000
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2685
	     */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2686
	    while (_l > 1) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2687
		unsigned int t;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2688
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2689
#if defined(LOAD_WORD_WISE)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2690
		/* better fetch short-wise */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2691
		t = ((unsigned short *)digitP)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2692
		digitP += 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2693
		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
  2694
#else
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2695
		t = (digitP[1]<<8) + digitP[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2696
		digitP += 2;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2697
#endif
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2698
		_prod = t * _v + _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2699
		_carry = _prod >> 16;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2700
#if defined(STORE_WORD_WISE)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2701
		/* better store short-wise */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2702
		_prod = ((_prod >> 8) | (_prod << 8)) & 0xFFFF;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2703
		((unsigned short *)resultP)[0] = _prod;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2704
#else
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2705
		resultP[0] = _prod /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2706
		resultP[1] = (_prod>>8) /* & 0xFF */;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2707
#endif
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2708
		resultP += 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2709
		_l -= 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2710
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2711
	}
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  2712
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  2713
#endif /* LSB_FIRST */
1797
8dafe47b33fd faster multiplication by an integer.
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
  2714
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2715
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2716
	 * rest is done byte-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2717
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2718
	while (_l > 0) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2719
	    _prod = *digitP++ * _v + _carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2720
	    *resultP++ = _prod /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2721
	    _carry = _prod >> 8;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2722
	    _l--;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2723
	}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2724
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2725
	_l = __intVal(lResult) - __intVal(len);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2726
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2727
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2728
	 * remaining carry
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2729
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2730
	while (_carry) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2731
	    *resultP++ = _carry /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2732
	    _carry >>= 8;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2733
	    _l--;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2734
	}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2735
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2736
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2737
	 * remaining zeros
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2738
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2739
	while (_l--) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2740
	    *resultP++ = 0;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2741
	}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2742
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2743
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2744
	 * need compress ?
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2745
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2746
	if (resultP[-1]) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2747
	    /*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2748
	     * no
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2749
	     */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2750
	    RETURN(result);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2751
	}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2752
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2753
	ok = true;
85
claus
parents: 77
diff changeset
  2754
    }
claus
parents: 77
diff changeset
  2755
%}.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2756
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2757
     fall back - normally not reached
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2758
     (could make it a primitive-failure as well)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2759
    "
85
claus
parents: 77
diff changeset
  2760
    ok ifFalse:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2761
	carry := 0.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2762
	1 to:len do:[:i |
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2763
	    prod := (digitByteArray basicAt:i) * val + carry.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2764
	    resultDigitByteArray basicAt:i put:(prod bitAnd:16rFF).
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2765
	    carry := prod bitShift:-8.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2766
	].
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2767
	[carry ~~ 0] whileTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2768
	    len := len + 1.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2769
	    resultDigitByteArray basicAt:len put:(carry bitAnd:16rFF).
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2770
	    carry := carry bitShift:-8
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2771
	].
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2772
	[len < lResult] whileTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2773
	    len := len + 1.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2774
	    resultDigitByteArray basicAt:len put:0
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  2775
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2776
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2777
    ^ result compressed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2778
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2779
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2780
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2781
    "sent, when anInteger does not know how to add the receiver.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2782
     Return the sum of the receiver and the argument, (which must be a SmallInteger)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2783
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2784
    anInteger > 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2785
	sign > 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2786
	    ^ self absFastPlus:anInteger sign:1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2787
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2788
	^ self absFastMinus:anInteger sign:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2789
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2790
    anInteger == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2791
	^ self
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2792
    ].
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2793
    sign > 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2794
	^ self absFastMinus:anInteger sign:1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2795
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2796
    ^ self absFastPlus:anInteger sign:-1
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2797
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2798
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2799
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2800
     12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2801
     -12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2802
     12345678901234567890 sumFromInteger:0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2803
     -12345678901234567890 sumFromInteger:0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2804
     12345678901234567890 sumFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2805
     12345678901234567890 sumFromInteger:-1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2806
     -12345678901234567890 sumFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2807
     -12345678901234567890 sumFromInteger:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2808
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2809
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2810
    "Modified: / 9.1.1998 / 13:27:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2811
! !
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2812
15577
cc63cd495a01 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15569
diff changeset
  2813
!LargeInteger methodsFor:'modulo arithmetic'!
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2814
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2815
plus32:aNumber
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2816
    "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
  2817
     The argument must be another SmallInteger.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2818
     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
  2819
     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
  2820
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2821
%{  /* NOCONTEXT */
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2822
    INT sum;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2823
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2824
    sum =  __unsignedLongIntVal(self) + __unsignedLongIntVal(aNumber);
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2825
#if __POINTER_SIZE__ == 8
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2826
    sum &= 0xFFFFFFFFL;
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2827
#endif
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2828
    RETURN ( __MKUINT(sum));
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2829
%}.
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2830
    self primitiveFailed
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2831
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2832
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2833
     16r7FFFFFFF + 1       ->  2147483648
15240
adde35a78b78 compression
Claus Gittinger <cg@exept.de>
parents: 15132
diff changeset
  2834
     16r7FFFFFFF plus32: 1 ->  -2147483648
12877
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2835
    "
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2836
! !
be732e8f6914 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12747
diff changeset
  2837
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2838
!LargeInteger methodsFor:'private'!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2839
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2840
absDestructiveSubtract:aLargeInteger
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2841
    "private helper for division:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2842
	destructively subtract aLargeInteger from myself
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2843
	AND return true, if the result is non-zero, false otherwise.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2844
	(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
  2845
	Does not care about the signs of the receiver and argument
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2846
	The receiver must be >= the argument.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2847
	The receiver must be a temporary scratch-number"
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2848
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2849
    |otherDigitByteArray
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2850
     len1   "{ Class: SmallInteger }"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2851
     len2   "{ Class: SmallInteger }"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2852
     index  "{ Class: SmallInteger }"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2853
     borrow "{ Class: SmallInteger }"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2854
     diff   "{ Class: SmallInteger }"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2855
     notZero
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2856
    |
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2857
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2858
    notZero := false.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2859
    len1 := digitByteArray size.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2860
    otherDigitByteArray := aLargeInteger digitBytes.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2861
    len2 := otherDigitByteArray size.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2862
    len2 > len1 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2863
	[(otherDigitByteArray at:len2) == 0] whileTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2864
	    len2 := len2 - 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2865
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2866
	len2 > len1 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2867
	    self error:'operation failed' "/ may not be called that way
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2868
	].
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2869
    ].
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2870
    "/ knowing that len2 is <= len1
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2871
%{
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2872
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2873
    OBJ _digitByteArray = __INST(digitByteArray);
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2874
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2875
    if (__isByteArray(_digitByteArray)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2876
     && __isByteArray(otherDigitByteArray)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2877
	int _len1 = __intVal(len1),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2878
	    _len2 = __intVal(len2);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2879
	unsigned char *_myDigits, *_otherDigits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2880
	int _index = 1, _borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2881
	INT _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2882
	int anyBitNonZero = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2883
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2884
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2885
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2886
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2887
#if defined(__LSBFIRST__)
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2888
# if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2889
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2890
	    int _len2Q;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2891
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2892
	     * subtract int-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2893
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2894
	    _len2Q = _len2-4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2895
	    while (_index <= _len2Q) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2896
		/* 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
  2897
		_diff = ((unsigned int *)(_myDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2898
		_diff -= ((unsigned int *)(_otherDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2899
		_diff -= _borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2900
		if (_diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2901
		    _borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2902
		} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2903
		    _borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2904
		    /* _diff += 0x100000000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2905
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2906
		((unsigned int *)(_myDigits+_index-1))[0] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2907
		anyBitNonZero |= (_diff & 0xFFFFFFFFL);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2908
		_index += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2909
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2910
	}
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2911
# endif
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2912
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2913
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2914
	 * subtract short-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2915
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2916
	while (_index < _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2917
	    /* 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
  2918
	    _diff = ((unsigned short *)(_myDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2919
	    _diff -= ((unsigned short *)(_otherDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2920
	    _diff -= _borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2921
	    if (_diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2922
		_borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2923
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2924
		_borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2925
		/* _diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2926
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2927
	    ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2928
	    anyBitNonZero |= (_diff & 0xFFFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2929
	    _index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2930
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2931
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2932
	if (_index <= _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2933
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2934
	     * cannot continue with shorts - there is an odd number of
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2935
	     * bytes in the minuent
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2936
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2937
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2938
	    while (_index < _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2939
		/* 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
  2940
		_diff = ((unsigned short *)(_myDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2941
		_diff -= _borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2942
		if (_diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2943
		    /* _borrow = 0; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2944
		    ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2945
		    anyBitNonZero |= (_diff & 0xFFFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2946
		    _index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2947
		    while (_index < _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2948
			anyBitNonZero |= ((unsigned short *)(_myDigits+_index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2949
			if (anyBitNonZero) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2950
			    RETURN (true);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2951
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2952
			_index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2953
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2954
		    /* last odd index */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2955
		    if (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2956
			anyBitNonZero |= _myDigits[_index - 1];;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2957
			if (anyBitNonZero) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2958
			    RETURN (true);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2959
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2960
			_index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2961
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2962
		    RETURN (anyBitNonZero ? true : false);
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
		_borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2965
		/* _diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2966
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2967
		((unsigned short *)(_myDigits+_index-1))[0] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2968
		anyBitNonZero |= (_diff & 0xFFFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2969
		_index += 2;
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
	}
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  2972
#endif
19262
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
	 * subtract byte-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2975
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2976
	while (_index <= _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2977
	    /* 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
  2978
	    _diff = _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2979
	    _diff -= _otherDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2980
	    _diff -= _borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2981
	    if (_diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2982
		_borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2983
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2984
		_borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2985
		/* _diff += 0x100; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2986
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2987
	    _myDigits[_index - 1] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2988
	    anyBitNonZero |= (_diff & 0xFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2989
	    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2990
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2991
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2992
	while (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2993
	    /* 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
  2994
	    _diff = _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2995
	    _diff -= _borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2996
	    if (_diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2997
		/* _borrow = 0; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2998
		_myDigits[_index - 1] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  2999
		anyBitNonZero |= (_diff & 0xFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3000
		_index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3001
		while (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3002
		    anyBitNonZero |= _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3003
		    if (anyBitNonZero) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3004
			RETURN (true);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3005
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3006
		    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3007
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3008
		break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3009
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3010
	    _borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3011
	    /* _diff += 0x100; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3012
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3013
	    _myDigits[_index - 1] = _diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3014
	    anyBitNonZero |= (_diff & 0xFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3015
	    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3016
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3017
	RETURN (anyBitNonZero ? true : false);
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3018
    }
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3019
%}.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3020
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3021
    index := 1.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3022
    borrow := 0.
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3023
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3024
    [index <= len1] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3025
	diff := borrow.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3026
	diff := diff + (digitByteArray basicAt:index).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3027
	index <= len2 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3028
	    diff := diff - (otherDigitByteArray basicAt:index).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3029
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3030
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3031
	"/ workaround for gcc code generator bug
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3032
	(diff >= 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3033
	    borrow := 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3034
	] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3035
	    borrow := -1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3036
	    diff := diff + 16r100
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3037
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3038
	diff ~~ 0 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3039
	    notZero := true
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3040
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3041
	digitByteArray basicAt:index put:diff.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3042
	index := index + 1
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3043
    ].
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3044
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3045
    ^ notZero
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3046
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3047
    "Created: / 5.11.1996 / 16:23:47 / cg"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3048
    "Modified: / 5.11.1996 / 18:56:50 / cg"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3049
    "Modified: / 27.4.1999 / 18:08:23 / stefan"
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3050
!
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3051
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3052
absDivMod:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3053
    "return an array with two LargeIntegers representing
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3054
     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
  3055
     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
  3056
     This method needs a rewrite."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3057
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3058
    |dividend divisor
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3059
     quo digits
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3060
     divModOrNil
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3061
     shift "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3062
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3063
    anInteger == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3064
	^ ZeroDivide raiseRequestWith:thisContext
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3065
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3066
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3067
    anInteger class == SmallInteger ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3068
	divisor := anInteger abs.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3069
	divModOrNil := self absFastDivMod:divisor.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3070
	divModOrNil notNil ifTrue:[^ divModOrNil].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3071
	divisor := divisor asLargeInteger.
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3072
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3073
	self = anInteger ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3074
	    ^ Array with:1 with:0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3075
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3076
	divisor := anInteger.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3077
    ].
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3078
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3079
    shift := self highBit - divisor highBit.
16124
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  3080
    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
  3081
    shift < 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3082
	^ Array with:0 with:dividend compressed.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3083
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3084
    shift == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3085
	divisor := self class digitBytes:(divisor digitBytes copy). "/ anInteger simpleDeepCopy.
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3086
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3087
	divisor := divisor bitShift:shift.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3088
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3089
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3090
    quo := self class basicNew numberOfDigits:((shift // 8) + 1).
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3091
    digits := quo digitBytes.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3092
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3093
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3094
    [shift > 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3095
	(dividend absLess:divisor) ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3096
	    digits bitSetAt:shift.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3097
	    (dividend absDestructiveSubtract: divisor) ifFalse:[ "result == 0"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3098
		^ Array with:quo compressed with:0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3099
	    ].
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
	shift := shift - 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3102
	divisor := divisor div2.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3103
    ].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3104
    ^ 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
  3105
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3106
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3107
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:4000000000] ]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3108
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:3000000000] ]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3109
     16000000000 absDivMod:4000000000
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3110
     16000000000 absDivMod:3000000000
19126
98adb7dc1950 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19102
diff changeset
  3111
     160000000000000000000000 absDivMod:160000000000000000000000
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3112
    "
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3113
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3114
    "Modified: / 5.11.1996 / 18:40:24 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3115
    "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
  3116
    "Modified: / 26.7.1999 / 10:46:36 / stefan"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3117
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3118
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3119
absEq:aLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3120
    "return true, if abs(self) = abs(theArgument)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3121
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3122
    |len1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3123
     len2 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3124
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3125
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3126
     otherDigitByteArray |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3127
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3128
%{  /* NOCONTEXT */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3129
    if (__isLargeInteger(aLargeInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3130
	OBJ _digitByteArray = __INST(digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3131
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3132
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3133
	if (__isByteArray(_digitByteArray)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3134
	 && __isByteArray(_otherDigitByteArray)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3135
	    INT _myLen = __byteArraySize(_digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3136
	    INT _otherLen = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3137
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3138
	    unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3139
	    unsigned char *_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3140
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3141
	    if (_myLen == _otherLen) {
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3142
tryAgain:
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3143
		while (_myLen >= (sizeof(INT)*4)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3144
		    if ( ((unsigned INT *)_myDigits)[0] != ((unsigned INT *)_otherDigits)[0]) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3145
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3146
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3147
		    if ( ((unsigned INT *)_myDigits)[1] != ((unsigned INT *)_otherDigits)[1]) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3148
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3149
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3150
		    if ( ((unsigned INT *)_myDigits)[2] != ((unsigned INT *)_otherDigits)[2]) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3151
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3152
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3153
		    if ( ((unsigned INT *)_myDigits)[3] != ((unsigned INT *)_otherDigits)[3]) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3154
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3155
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3156
		    _myDigits += sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3157
		    _otherDigits += sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3158
		    _myLen -= sizeof(INT)*4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3159
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3160
		while (_myLen >= (sizeof(INT))) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3161
		    if ( *(unsigned INT *)_myDigits != *(unsigned INT *)_otherDigits) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3162
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3163
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3164
		    _myDigits += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3165
		    _otherDigits += sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3166
		    _myLen -= sizeof(INT);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3167
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3168
		while (_myLen > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3169
		    if ( *_myDigits != *_otherDigits) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3170
			RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3171
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3172
		    _myDigits++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3173
		    _otherDigits++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3174
		    _myLen--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3175
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3176
		RETURN(true);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3177
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3178
	    /* care for unnormalized ints */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3179
	    while ((_myLen > 0) && (_myDigits[_myLen-1] == 0)) _myLen--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3180
	    while ((_otherLen > 0) && (_otherDigits[_otherLen-1] == 0)) _otherLen--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3181
	    if (_myLen == _otherLen) goto tryAgain;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3182
	    RETURN(false);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3183
	}
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3184
    }
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3185
%}.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3186
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3187
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3188
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3189
    len2 := otherDigitByteArray size.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3190
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3191
    "/ the highest digit(s) should not be zero
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3192
    "/ when properly normalized;
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3193
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3194
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3195
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3196
    [(digitByteArray basicAt:len1) == 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3197
	len1 := len1 - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3198
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3199
    [(otherDigitByteArray basicAt:len2) == 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3200
	len2 := len2 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3201
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3202
    (len1 ~~ len2) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3203
    [len1 > 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3204
	d1 := digitByteArray basicAt:len1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3205
	d2 := otherDigitByteArray basicAt:len1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3206
	(d1 ~~ d2) ifTrue:[^ false].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3207
	len1 := len1 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3208
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3209
    ^ true
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3210
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3211
    "Modified: / 8.5.1999 / 18:37:02 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3212
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3213
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3214
absFastDivMod:aPositiveSmallInteger
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3215
    "return an array with two LargeIntegers representing
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3216
	abs(self) // aPositiveSmallInteger and
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3217
	abs(self) \\ aPositiveSmallInteger
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3218
     or nil, if not computed by optimized code"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3219
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3220
    |tmp1     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3221
     prevRest "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3222
     count    "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  3223
     newDigitByteArray result
claus
parents: 77
diff changeset
  3224
     ok|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3225
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3226
    aPositiveSmallInteger == 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3227
	^ ZeroDivide raiseRequestWith:thisContext
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3228
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3229
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3230
"This cannot happen (if always normalized)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3231
    self < aPositiveSmallInteger ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3232
	^ Array with:0 with:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3233
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3234
"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3235
    count := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3236
    result := self class basicNew numberOfDigits:count.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3237
    newDigitByteArray := result digitBytes.
85
claus
parents: 77
diff changeset
  3238
    ok := false.
claus
parents: 77
diff changeset
  3239
%{
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  3240
    OBJ __digits;
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  3241
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  3242
    __digits = __INST(digitByteArray);
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  3243
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  3244
    if (__isByteArray(__digits)
85
claus
parents: 77
diff changeset
  3245
     && __isByteArray(newDigitByteArray)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3246
     && __bothSmallInteger(count, aPositiveSmallInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3247
	unsigned INT rest = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3248
	int index = __intVal(count);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3249
	int index0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3250
	unsigned INT divisor = __intVal(aPositiveSmallInteger);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3251
	unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3252
	unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3253
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3254
	index0 = index - 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3255
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3256
	// at least one byte of value must remain when dividing
19256
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3257
# if (__POINTER_SIZE__ == 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3258
	if (divisor > 0xFFFFFFFFFFFFFF) RETURN(nil);
19256
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3259
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3260
	if (divisor > 0xFFFFFF) RETURN(nil);
19256
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3261
# endif
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3262
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3263
# if (__POINTER_SIZE__ == 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3264
	if (sizeof(int) == 4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3265
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3266
	     * divide int-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3267
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3268
	    if (divisor <= 0xFFFFFFFF) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3269
		if ((index & 3) == 0) { /* even number of int32's */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3270
		    while (index > 3) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3271
			unsigned INT t;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3272
			unsigned INT div;
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 -= 4;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3275
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3276
			t = *((unsigned int *)(&digitBytes[index]));
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3277
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3278
			t = digitBytes[index+3];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3279
			t = (t << 8) | digitBytes[index+2];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3280
			t = (t << 8) | digitBytes[index+1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3281
			t = (t << 8) | digitBytes[index];
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3282
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3283
			t = t | (rest << 32);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3284
			div = t / divisor;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3285
			rest = t % divisor;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3286
# if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3287
			*((unsigned int *)(&resultBytes[index])) = (div & 0xFFFFFFFF);
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3288
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3289
			resultBytes[index+3] = div >> 24;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3290
			resultBytes[index+2] = div >> 16;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3291
			resultBytes[index+1] = div >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3292
			resultBytes[index] = div /* & 0xFF */;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3293
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3294
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3295
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3296
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3297
	}
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  3298
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3299
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3300
	 * divide short-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3301
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3302
	if (divisor <= 0xFFFF) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3303
	    if ((index & 1) == 0) { /* even number of bytes */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3304
		while (index > 1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3305
		    unsigned INT t;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3306
		    unsigned INT div;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3307
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3308
		    index -= 2;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3309
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3310
		    t = *((unsigned short *)(&digitBytes[index]));
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3311
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3312
		    t = digitBytes[index+1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3313
		    t = (t << 8) | digitBytes[index];
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3314
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3315
		    t = t | (rest << 16);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3316
		    div = t / divisor;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3317
		    rest = t % divisor;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3318
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3319
		    *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3320
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3321
		    resultBytes[index+1] = div >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3322
		    resultBytes[index] = div /* & 0xFF */;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  3323
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3324
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3325
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3326
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3327
	while (index > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3328
	    unsigned INT t;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3329
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3330
	    index--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3331
	    t = digitBytes[index];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3332
	    t = t | (rest << 8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3333
	    resultBytes[index] = t / divisor;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3334
	    rest = t % divisor;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3335
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3336
	prevRest = __mkSmallInteger(rest);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3337
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3338
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3339
	 * no need to normalize ?
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3340
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3341
	index = index0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3342
	while ((index >= sizeof(INT)) && (resultBytes[index]==0)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3343
	    index--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3344
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3345
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3346
	if (index == index0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3347
	    if (index > sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3348
		RETURN ( __ARRAY_WITH2(result, prevRest));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3349
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3350
	    if ((index == sizeof(INT))
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3351
	     && resultBytes[index0] >= 0x40) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3352
		RETURN ( __ARRAY_WITH2(result, prevRest));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3353
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3354
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3355
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3356
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3357
	 * must compress
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3358
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3359
	ok = true;
85
claus
parents: 77
diff changeset
  3360
    }
claus
parents: 77
diff changeset
  3361
%}.
claus
parents: 77
diff changeset
  3362
    "
claus
parents: 77
diff changeset
  3363
     slow code - not normally reached
claus
parents: 77
diff changeset
  3364
     (could also do a primitiveFailure here)
claus
parents: 77
diff changeset
  3365
    "
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3366
    ok ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  3367
	^ Array with:(result compressed) with:prevRest
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3368
    ].
19254
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3369
    ^ nil
3ae994a58578 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19162
diff changeset
  3370
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3371
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3372
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3373
     16r123412341234 asLargeInteger absDivMod:(LargeInteger value:10)
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  3374
     ((16r1234 asLargeInteger absFastDivMod:16rffff) at:2) printStringRadix:16
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3375
     ((16r00123456 asLargeInteger absFastDivMod:16rffffff) at:2) printStringRadix:16
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3376
     ((666666666666666666 asLargeInteger absFastDivMod:16r3))
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3377
     ((1666666666 asLargeInteger absFastDivMod:16r3))
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3378
    "
19256
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3379
91884b166d88 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19254
diff changeset
  3380
    "Modified: / 26-02-2016 / 19:27:13 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3381
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3382
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  3383
absFastMinus:aSmallInteger sign:newSign
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  3384
    "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
  3385
     with sign: newSign.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  3386
     The result is normalized.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  3387
     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
  3388
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3389
    |result resultDigitByteArray lastDigit ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3390
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3391
     rsltLen "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3392
     index   "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3393
     borrow  "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3394
     diff    "{ Class: SmallInteger }" |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3395
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3396
    "/ the following code only works with
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3397
    "/ 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
  3398
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3399
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3400
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3401
	^ self absMinus:(self class value:aSmallInteger) sign:newSign.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3402
    ].
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3403
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3404
    len := digitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3405
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  3406
    rsltLen := len "+ 1".
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3407
    result := self class basicNew numberOfDigits:rsltLen sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3408
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3409
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3410
    borrow := aSmallInteger abs.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3411
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3412
%{
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3413
    if (__isByteArray(__INST(digitByteArray))
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3414
     && __isByteArray(resultDigitByteArray)) {
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3415
	unsigned INT __borrow = __intVal(borrow);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3416
	INT __diff;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3417
	int __index = 1;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3418
	int __len = __intVal(len);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3419
	unsigned char *__digitP = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3420
	unsigned char *__resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3421
	int __len3;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  3422
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3423
#if defined(__LSBFIRST__)
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3424
# if (__POINTER_SIZE__ == 8)
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3425
	/*
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3426
	 * subtract int-wise
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3427
	 */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3428
	__len3 = __len - 3;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3429
	while (__index < __len3) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3430
	    /* 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
  3431
	    __diff = ((unsigned int *)(__digitP + __index-1))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3432
	    __diff -= (__borrow & 0xFFFFFFFFL);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3433
	    __borrow >>= 32;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3434
	    ((unsigned int *)(__resultP+__index-1))[0] = __diff;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3435
	    __index += 4;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3436
	    if (__diff < 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3437
		/* __diff += 0x100000000; */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3438
		__borrow++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3439
	    } else {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3440
		if (__borrow == 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3441
		    /* nothing more to subtract .. */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3442
		    while (__index < __len3) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3443
			((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
  3444
			__index += 4;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3445
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3446
		    if (__index < __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3447
			((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
  3448
			__index += 2;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3449
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3450
		    if (__index <= __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3451
			__resultP[__index-1] = __digitP[__index-1];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3452
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3453
		    break;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3454
		}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3455
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3456
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3457
# endif
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3458
	/*
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3459
	 * subtract short-wise
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
	while (__index < __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3462
	    /* 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
  3463
	    __diff = ((unsigned short *)(__digitP+__index-1))[0];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3464
	    __diff -= (__borrow & 0xFFFF);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3465
	    __borrow >>= 16;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3466
	    ((unsigned short *)(__resultP+__index-1))[0] = __diff;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3467
	    __index += 2;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3468
	    if (__diff < 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3469
		/* __diff += 0x10000; */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3470
		__borrow++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3471
	    } else {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3472
		if (__borrow == 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3473
		    /* nothing more to subtract .. */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3474
		    while (__index < __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3475
			((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
  3476
			__index += 2;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3477
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3478
		    if (__index <= __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3479
			__resultP[__index-1] = __digitP[__index-1];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3480
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3481
		    break;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3482
		}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3483
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3484
	}
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  3485
#endif
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3486
	/*
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3487
	 * subtract byte-wise
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3488
	 */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3489
	while (__index <= __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3490
	    __diff = __digitP[__index-1];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3491
	    __diff -= (__borrow & 0xFF);
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3492
	    __borrow >>= 8;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3493
	    __resultP[__index-1] = __diff;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3494
	    __index++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3495
	    if (__diff < 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3496
		/* __diff += 0x100; */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3497
		__borrow++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3498
	    } else {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3499
		if (__borrow == 0) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3500
		    /* nothing more to subtract .. */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3501
		    while (__index <= __len) {
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3502
			__resultP[__index-1] = __digitP[__index-1];
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3503
			__index++;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3504
		    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3505
		    break;
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3506
		}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3507
	    }
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3508
	}
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3509
	lastDigit = __mkSmallInteger( __resultP[__index-1-1] );
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3510
	ok = true;
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3511
    }
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3512
%}.
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  3513
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  3514
    ok == true ifFalse:[        "/ cannot happen
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3515
	index := 1.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3516
	[borrow ~~ 0] whileTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3517
	    (index <= len) ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3518
		diff := (digitByteArray basicAt:index) - (borrow bitAnd:16rFF).
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3519
		borrow := borrow bitShift:-8.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3520
		diff < 0 ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3521
		    diff := diff + 256.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3522
		    borrow := borrow + 1.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3523
		]
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3524
	    ] ifFalse:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3525
		diff := borrow bitAnd:255.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3526
		borrow := borrow bitShift:-8.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3527
	    ].
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3528
	    resultDigitByteArray basicAt:index put:(lastDigit := diff).
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3529
	    index := index + 1
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3530
	].
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3531
	[index <= len] whileTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3532
	    resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3533
	    index := index + 1
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3534
	].
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3535
	(index <= rsltLen) ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3536
	    lastDigit := 0.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3537
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3538
    ].
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  3539
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3540
    (lastDigit == 0 or:[rsltLen <= SmallInteger maxBytes]) ifTrue:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3541
	^ result compressed.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3542
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3543
    ^ result
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3544
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3545
    "
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3546
     12345678900000000000 absFastMinus:1 sign:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3547
     12345678900000000000 absFastMinus:1 sign:-1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3548
     12345678900000000000 absFastMinus:1000000 sign:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3549
     12345678900000000000 absFastMinus:255 sign:1
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  3550
     (SmallInteger maxVal + 1) absFastMinus:1 sign:1
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3551
     (SmallInteger minVal - 1) absFastMinus:1 sign:1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3552
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  3553
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3554
    "Modified: 24.3.1997 / 21:33:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3555
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3556
21986
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3557
absFastMod:aPositiveSmallInteger
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3558
    "return abs(self) \\ aPositiveSmallInteger
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3559
     or nil, if not computed by optimized code"
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3560
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3561
    |count|
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3562
    
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3563
    aPositiveSmallInteger == 0 ifTrue:[
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3564
        ^ ZeroDivide raiseRequestWith:thisContext
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3565
    ].
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3566
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3567
    count := digitByteArray size.
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3568
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3569
"This cannot happen (if always normalized)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3570
    self < aPositiveSmallInteger ifTrue:[
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3571
        ^ Array with:0 with:self
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3572
    ].
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3573
"
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3574
%{
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3575
    OBJ __digits;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3576
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3577
    __digits = __INST(digitByteArray);
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3578
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3579
    if (__isByteArray(__digits)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3580
     && __bothSmallInteger(count, aPositiveSmallInteger)) {
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3581
        unsigned INT rest = 0;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3582
        int index = __intVal(count);
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3583
        int index0;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3584
        unsigned INT divisor = __intVal(aPositiveSmallInteger);
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3585
        unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3586
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3587
        index0 = index - 1;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3588
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3589
        // at least one byte of value must remain when dividing
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3590
# if (__POINTER_SIZE__ == 8)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3591
        if (divisor > 0xFFFFFFFFFFFFFF) RETURN(nil);
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3592
# else
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3593
        if (divisor > 0xFFFFFF) RETURN(nil);
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3594
# endif
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3595
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3596
# if (__POINTER_SIZE__ == 8)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3597
        if (sizeof(int) == 4) {
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3598
            /*
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3599
             * divide int-wise
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3600
             */
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3601
            if (divisor <= 0xFFFFFFFF) {
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3602
                if ((index & 3) == 0) { /* even number of int32's */
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3603
                    while (index > 3) {
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3604
                        unsigned INT t;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3605
                        // unsigned INT div;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3606
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3607
                        index -= 4;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3608
# if defined(__LSBFIRST__)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3609
                        t = *((unsigned int *)(&digitBytes[index]));
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3610
# else
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3611
                        t = digitBytes[index+3];
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3612
                        t = (t << 8) | digitBytes[index+2];
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3613
                        t = (t << 8) | digitBytes[index+1];
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3614
                        t = (t << 8) | digitBytes[index];
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3615
# endif
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3616
                        t = t | (rest << 32);
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3617
                        // div = t / divisor;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3618
                        rest = t % divisor;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3619
                    }
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3620
                }
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3621
            }
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3622
        }
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3623
#endif
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3624
        /*
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3625
         * divide short-wise
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3626
         */
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3627
        if (divisor <= 0xFFFF) {
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3628
            if ((index & 1) == 0) { /* even number of bytes */
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3629
                while (index > 1) {
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3630
                    unsigned INT t;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3631
                    // unsigned INT div;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3632
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3633
                    index -= 2;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3634
#if defined(__LSBFIRST__)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3635
                    t = *((unsigned short *)(&digitBytes[index]));
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3636
#else
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3637
                    t = digitBytes[index+1];
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3638
                    t = (t << 8) | digitBytes[index];
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3639
#endif
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3640
                    t = t | (rest << 16);
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3641
                    // div = t / divisor;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3642
                    rest = t % divisor;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3643
                }
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3644
            }
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3645
        }
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3646
        while (index > 0) {
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3647
            unsigned INT t;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3648
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3649
            index--;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3650
            t = digitBytes[index];
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3651
            t = t | (rest << 8);
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3652
            // resultBytes[index] = t / divisor;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3653
            rest = t % divisor;
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3654
        }
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3655
        RETURN ( __mkSmallInteger(rest) );
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3656
    }
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3657
%}.
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3658
    ^ nil
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3659
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3660
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3661
    "
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3662
     16r123412341234 asLargeInteger absFastDivMod:10 #(2001485300178 0)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3663
     16r123412341234 asLargeInteger absFastMod:10
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3664
     
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3665
     ((16r1234 asLargeInteger absFastDivMod:16rffff) at:2)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3666
     (16r1234 asLargeInteger absFastMod:16rffff)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3667
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3668
     ((16r00123456 asLargeInteger absFastDivMod:16rffffff) at:2)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3669
     (16r00123456 asLargeInteger absFastMod:16rffffff) 
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3670
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3671
     (666666666666666666 asLargeInteger absFastDivMod:16r3)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3672
     (666666666666666666 asLargeInteger absFastMod:16r3)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3673
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3674
     (1666666666 asLargeInteger absFastDivMod:16r3)
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3675
     ((1666666666 asLargeInteger absFastMod:16r3))
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3676
    "
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3677
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3678
    "Created: / 05-07-2017 / 13:58:23 / cg"
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3679
!
ff209ce4ed7f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21985
diff changeset
  3680
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  3681
absFastPlus:aSmallInteger sign:newSign
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3682
    "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
  3683
     with sign: newSign.
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  3684
     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
  3685
     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
  3686
     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
  3687
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  3688
    |result resultDigitByteArray lastDigit
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3689
     ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3690
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3691
     rsltLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3692
     index "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3693
     carry "{ Class: SmallInteger }" |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3694
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3695
    "/ the following code only works with
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3696
    "/ 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
  3697
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3698
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3699
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3700
	^ self absPlus:(self class value:aSmallInteger) sign:newSign.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3701
    ].
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  3702
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3703
    len := rsltLen := digitByteArray size.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3704
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3705
    "/ 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
  3706
    "/ 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
  3707
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3708
    (digitByteArray at:len) == 16rFF ifTrue:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3709
	rsltLen := len + 1.
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  3710
    ] ifFalse:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3711
	"/ 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
  3712
%{
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3713
#if __POINTER_SIZE__ == 8
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3714
	if (__intVal(aSmallInteger) & 0xFF00000000000000L) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3715
	    rsltLen = __mkSmallInteger(__intVal(len) + 1);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3716
	}
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  3717
#else
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3718
	if (__intVal(aSmallInteger) & 0xFF000000) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3719
	    rsltLen = __mkSmallInteger(__intVal(len) + 1);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3720
	}
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  3721
#endif
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  3722
%}
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3723
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3724
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  3725
    result := self class basicNew numberOfDigits:rsltLen sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3726
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3727
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3728
%{
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3729
    if (__isByteArray(__INST(digitByteArray))
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3730
     && __isByteArray(resultDigitByteArray)
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3731
     && __isSmallInteger(aSmallInteger)) {
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3732
	/* carry is NOT unsigned (see negation below) */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3733
	INT __carry = __intVal(aSmallInteger);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3734
	int __index = 1;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3735
	int __len = __intVal(len);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3736
	unsigned char *__src = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3737
	unsigned char *__dst = (unsigned char *)(__ByteArrayInstPtr(resultDigitByteArray)->ba_element);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3738
	INT __ptrDelta = __dst - __src;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3739
	unsigned char *__srcLast = __src + __len - 1;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3740
	int __rsltLen = __intVal(rsltLen);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3741
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3742
	if (__carry < 0) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3743
	    __carry = -__carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3744
	}
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  3745
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3746
#if defined(__LSBFIRST__)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3747
# if defined(__i386__) && defined(__GNUC__) && (__POINTER_SIZE__ == 4)
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3748
#  if 0 /* NOTICE - the code below is 20% slower ... - why */
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3749
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3750
	 * add long-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3751
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3752
	asm("  jecxz nothingToDo                                      \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3753
	       movl  %%eax, %%esi      /* __src input */              \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3754
	       movl  %%ebx, %%edi      /* __dst input */              \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3755
								      \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3756
	       /* the first 4-byte int */                             \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3757
	       lodsl                   /* fetch */                    \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3758
	       addl  %%edx, %%eax      /* add */                      \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3759
	       stosl                   /* store */                    \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3760
	       leal  -1(%%ecx),%%ecx   /* do not clobber carry */     \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3761
	       jecxz doneLoop          /* any more ? */               \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3762
	       /* remaining 4-byte ints */                            \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3763
	       jmp   addLoop                                          \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3764
								      \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3765
	       .align 8                                               \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3766
	     addLoop:                                                 \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3767
	       movl  0(%%esi), %%ebx   /* fetch  */                   \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3768
	       jnc   copyLoop2                                        \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3769
	       movl  $0, %%eax                                        \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3770
	       leal  4(%%esi), %%esi                                  \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3771
	       adcl  %%ebx, %%eax      /* & add carry from prev int */\n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3772
	       leal  8(%%edi), %%edi                                  \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3773
	       movl  %%eax, -8(%%edi)  /* store */                    \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3774
	       leal  -1(%%ecx),%%ecx   /* do not clobber carry */     \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3775
	       jecxz doneLoop          /* any more ? */               \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3776
								      \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3777
	       movl  0(%%esi), %%ebx   /* fetch  */                   \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3778
	       movl  $0, %%eax                                        \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3779
	       leal  4(%%esi), %%esi                                  \
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3780
	       adcl  %%ebx, %%eax      /* & add carry from prev int */\n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3781
	       movl  %%eax, -4(%%edi)  /* store */                    \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3782
								      \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3783
	       loop  addLoop                                          \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3784
	       jmp   doneLoop                                         \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3785
								      \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3786
	       .align 8                                               \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3787
	     copyLoop:                                                \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3788
	       movl  0(%%esi), %%ebx                                  \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3789
	     copyLoop2:                                               \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3790
	       add   $4, %%esi                                        \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3791
	       add   $4, %%edi                                        \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3792
	       movl  %%ebx, -4(%%edi)                                 \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3793
	       loop  copyLoop                                         \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3794
								      \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3795
	     doneLoop:                                                \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3796
	       movl  $0, %%edx         /* do not clobber carry (xorl clears it) */   \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3797
	       adcl  $0, %%edx                                        \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3798
	       movl  %%esi, %%eax      /* __src output */             \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3799
	     nothingToDo:                                             \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3800
	    " : "=d"  (ASM_ULONGCAST(__carry)),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3801
		"=a"  (__src)
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3802
	      : "1"   (__src),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3803
		"b"   (__dst),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3804
		"c"   (__len / 4),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3805
		"0"   (__carry)
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3806
	      : "esi", "edi");
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3807
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3808
#  else
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3809
	{
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3810
	    unsigned char *__srcLastX;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3811
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3812
	    __srcLastX = __srcLast - 3 - 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3813
	    while (__src <= __srcLastX) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3814
		unsigned int __sum, __sum2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3815
		unsigned __digit1, __digit2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3816
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3817
		__digit1 = ((unsigned *)__src)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3818
		__digit2 = ((unsigned *)__src)[1];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3819
		asm ("addl %%edx,%%ecx          \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3820
		      adcl $0, %%eax            \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3821
		      movl $0, %%edx            \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3822
		      adcl $0, %%edx"
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3823
			: "=d"  (ASM_ULONGCAST(__carry)),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3824
			  "=c"  (ASM_ULONGCAST(__sum)),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3825
			  "=a"  (ASM_ULONGCAST(__sum2))
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3826
			: "0"   (ASM_ULONGCAST(__carry)),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3827
			  "1"   (__digit1),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3828
			  "2"   (__digit2));
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3829
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3830
		((unsigned int *)(__src + __ptrDelta))[0] = __sum;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3831
		((unsigned int *)(__src + __ptrDelta))[1] = __sum2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3832
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3833
		__src += 8;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3834
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3835
		if (__carry == 0) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3836
		    while (__src <= __srcLastX) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3837
			/* copy over words */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3838
			((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3839
			((unsigned int *)(__src + __ptrDelta))[1] = ((unsigned int *)__src)[1];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3840
			__src += 8;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3841
		    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3842
		    while (__src <= __srcLast) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3843
			/* copy over bytes */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3844
			__src[__ptrDelta] = __src[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3845
			__src ++;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3846
		    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3847
		    goto doneSource;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3848
		}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3849
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3850
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3851
	    __srcLastX = __srcLastX + 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3852
	    if (__src <= __srcLastX) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3853
		unsigned int __sum, __digit;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3854
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3855
		__digit = ((unsigned *)__src)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3856
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3857
		asm ("addl %%eax,%%edx  \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3858
		      movl $0,%%eax     \n\
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3859
		      adcl $0,%%eax"
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3860
			: "=a"  (ASM_ULONGCAST(__carry)),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3861
			  "=d"  (ASM_ULONGCAST(__sum))
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3862
			: "0"   (ASM_ULONGCAST(__carry)),
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3863
			  "1"   (__digit) );
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3864
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3865
		((unsigned int *)(__src + __ptrDelta))[0] = __sum;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3866
		__src += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3867
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3868
		if (__carry == 0) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3869
		    while (__src <= __srcLast) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3870
			/* copy over bytes */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3871
			__src[__ptrDelta] = __src[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3872
			__src ++;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3873
		    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3874
		    goto doneSource;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3875
		}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3876
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3877
	}
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3878
#  endif
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3879
# else /* not i386-GNUC */
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  3880
#  if defined(__win32__) && defined(__BORLANDC__) && defined(__x86__) && (__POINTER_SIZE__ == 4)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3881
	{
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3882
	    unsigned char *__srcLast4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3883
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3884
	    /*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3885
	     * add long-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3886
	     */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3887
	    __srcLast4 = __srcLast - 3;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3888
	    while (__src <= __srcLast4) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3889
		unsigned int __sum;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3890
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3891
		__sum = ((unsigned int *)__src)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3892
		asm {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3893
		      mov eax, __sum
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3894
		      add eax, __carry
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3895
		      mov edx, 0
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3896
		      adc edx, 0
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3897
		      mov __sum, eax
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3898
		      mov __carry, edx
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3899
		    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3900
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3901
		((unsigned int *)(__src + __ptrDelta))[0] = __sum;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3902
		__src += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3903
		if (__carry == 0) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3904
		    while (__src <= __srcLast4) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3905
			/* copy over words */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3906
			((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3907
			__src += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3908
		    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3909
		    while (__src <= __srcLast) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3910
			/* copy over bytes */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3911
			__src[__ptrDelta] = __src[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3912
			__src ++;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3913
		    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3914
		    goto doneSource;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3915
		}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3916
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3917
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3918
#  else /* not i386-WIN32 */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3919
#   if defined(__LSBFIRST__) && (__POINTER_SIZE__ == 8)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3920
	{
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3921
	    unsigned char *__srcLast4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3922
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3923
	    /*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3924
	     * add long-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3925
	     */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3926
	    __srcLast4 = __srcLast - 3;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3927
	    while (__src <= __srcLast4) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3928
		unsigned INT __sum;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3929
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3930
		__sum = (INT)(((unsigned int *)__src)[0]);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3931
		__sum += __carry;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3932
		((unsigned int *)(__src + __ptrDelta))[0] = __sum /* & 0xFFFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3933
		__src += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3934
		__carry = __sum >> 32;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3935
		if (__carry == 0) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3936
		    while (__src <= __srcLast4) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3937
			/* copy over words */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3938
			((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3939
			__src += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3940
		    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3941
		    while (__src <= __srcLast) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3942
			/* copy over bytes */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3943
			__src[__ptrDelta] = __src[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3944
			__src ++;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3945
		    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3946
		    goto doneSource;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3947
		}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3948
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3949
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3950
#   endif /* LSB+64bit */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3951
#  endif /* __i386__ & WIN32 */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3952
# endif /* __i386__ & GNUC */
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  3953
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3954
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3955
	 * add short-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3956
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3957
	while (__src < __srcLast) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3958
	    __carry += ((unsigned short *)__src)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3959
	    ((unsigned short *)(__src + __ptrDelta))[0] = __carry /* & 0xFFFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3960
	    __carry >>= 16;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3961
	    __src += 2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3962
	}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3963
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3964
	 * last (odd) byte
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3965
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3966
	if (__src <= __srcLast) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3967
	    __carry += __src[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3968
	    __src[__ptrDelta] = __carry /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3969
	    __carry >>= 8;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3970
	    __src++;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3971
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3972
#else /* not __LSBFIRST__ */
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  3973
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3974
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3975
	 * add byte-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3976
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3977
	while (__src <= __srcLast) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3978
	    __carry += __src[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3979
	    __src[__ptrDelta] = __carry /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3980
	    __src++;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3981
	    __carry >>= 8;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3982
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3983
	    if (__carry == 0) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3984
		while (__src <= __srcLast) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3985
		    /* copy over rest */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3986
		    __src[__ptrDelta] = __src[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3987
		    __src++;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3988
		}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3989
		goto doneSource;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3990
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3991
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3992
#endif /* __LSBFIRST__ */
4185
375439993eb7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4182
diff changeset
  3993
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  3994
    doneSource: ;
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3995
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3996
	 * now, at most one other byte is to be stored ...
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3997
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3998
	if (__len < __rsltLen) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  3999
	    __src[__ptrDelta] = __carry /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4000
	    __src++;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4001
	}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4002
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4003
	if (__src[__ptrDelta-1] != 0) {      /* lastDigit */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4004
	    RETURN (result);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4005
	}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4006
	// must compress
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4007
	ok = true;
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  4008
    }
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  4009
%}.
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  4010
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  4011
    ok ~~ true ifTrue:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4012
	index := 1.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4013
	carry := aSmallInteger abs.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4014
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4015
	[carry ~~ 0] whileTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4016
	    (index <= len) ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4017
		carry := (digitByteArray basicAt:index) + carry.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4018
	    ].
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4019
	    resultDigitByteArray basicAt:index put:(lastDigit := carry bitAnd:16rFF).
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4020
	    carry := carry bitShift:-8.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4021
	    index := index + 1
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4022
	].
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4023
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4024
	(index <= rsltLen) ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4025
	    [index <= len] whileTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4026
		resultDigitByteArray basicAt:index put:(digitByteArray basicAt:index).
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4027
		index := index + 1
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4028
	    ].
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4029
	    lastDigit := 0.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4030
	].
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4031
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4032
	(lastDigit ~~ 0 and:[rsltLen > SmallInteger maxBytes]) ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4033
	    ^ result
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4034
	].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4035
    ].
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  4036
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  4037
    ^ result compressed
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  4038
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  4039
    "Modified: 24.3.1997 / 21:32:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4040
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4041
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4042
absLess:aLargeInteger
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4043
    "return true, if abs(self) < abs(theArgument).
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4044
     This handles unnormalized largeIntegers."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4045
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4046
    |myLen "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4047
     otherLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4048
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4049
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4050
     otherDigitByteArray |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4051
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4052
%{  /* NOCONTEXT */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4053
#if defined(__LSBFIRST__)
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4054
    if (__isByteArray(__INST(digitByteArray))
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4055
     && __isLargeInteger(aLargeInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4056
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4057
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4058
	if (__isByteArray(_otherDigitByteArray)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4059
	    unsigned char *_myDigits = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4060
	    unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4061
	    INT _myLen = __byteArraySize(__INST(digitByteArray));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4062
	    INT _otherLen = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4063
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4064
	    if (_myLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4065
		if (_otherLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4066
		    unsigned INT _myVal = *((unsigned INT *)_myDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4067
		    unsigned INT _otherVal = *((unsigned INT *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4068
		    RETURN( (_myVal < _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4069
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4070
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4071
# if defined(UINT64) && (__POINTER_SIZE__ != 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4072
	    if (_myLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4073
		if (_otherLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4074
		    UINT64 _myVal = (UINT64)(*((UINT *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4075
		    UINT64 _otherVal = *((UINT64 *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4076
		    RETURN( (_myVal < _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4077
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4078
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4079
		if (_myLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4080
		    if (_otherLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4081
			UINT64 _myVal = (*((UINT64 *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4082
			UINT64 _otherVal = *((UINT64 *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4083
			RETURN( (_myVal < _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4084
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4085
		    if (_otherLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4086
			UINT64 _myVal = (*((UINT64 *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4087
			UINT64 _otherVal = (UINT64) *((UINT *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4088
			RETURN( (_myVal < _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4089
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4090
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4091
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4092
# endif /* UINT64 */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4093
	    while ((_myLen > 0) && (_myDigits[_myLen-1] == 0)) _myLen--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4094
	    while ((_otherLen > 0) && (_otherDigits[_otherLen-1] == 0)) _otherLen--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4095
	    if (_myLen < _otherLen) { RETURN( true ); }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4096
	    if (_myLen > _otherLen) { RETURN (false ); }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4097
	    while (_myLen-- > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4098
		unsigned char _d1 = _myDigits[_myLen];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4099
		unsigned char _d2 = _otherDigits[_myLen];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4100
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4101
		if (_d1 != _d2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4102
		    if (_d1 < _d2) { RETURN( true ); }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4103
		    RETURN (false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4104
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4105
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4106
	    RETURN (false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4107
	}
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4108
    }
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4109
#endif /* LSBFIRST */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4110
%}.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4111
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4112
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4113
    otherDigitByteArray := aLargeInteger digitBytes.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4114
    otherLen := otherDigitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4115
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4116
    "/ the highest digit(s) should not be zero
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4117
    "/ when properly normalized;
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4118
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4119
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4120
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4121
    [myLen > 0 and:[(digitByteArray basicAt:myLen) == 0]] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4122
	myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4123
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4124
    [otherLen > 0 and:[(otherDigitByteArray basicAt:otherLen) == 0]] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4125
	otherLen := otherLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4126
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4127
    (myLen < otherLen) ifTrue:[^ true].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4128
    (myLen > otherLen) ifTrue:[^ false].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4129
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4130
    [myLen > 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4131
	d1 := digitByteArray basicAt:myLen.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4132
	d2 := otherDigitByteArray basicAt:myLen.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4133
	d1 == d2 ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4134
	    (d1 < d2) ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4135
	    ^ false
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4136
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4137
	myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4138
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4139
    ^ false
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4140
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4141
    "
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4142
     |a b|
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4143
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4144
     a := 16rFEFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4145
     b := 16rFFFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4146
     Time millisecondsToRun:[
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4147
       10000000 timesRepeat:[ a absLess_old:b ]
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4148
     ]    1185 1233 1185
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4149
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4150
     |a b|
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4151
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4152
     a := 16rFEFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4153
     b := 16rFFFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4154
     Time millisecondsToRun:[
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4155
       10000000 timesRepeat:[ a absLess_n:b ]
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  4156
     ] 686 655 702 702
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4157
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4158
     16rEFFFFFFF  absLess_n: 16rFFFFFFFF
11927
75c9deec4a70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11731
diff changeset
  4159
     16rEFFFFFFF  absLess: 16rFFFFFFFF
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4160
    "
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4161
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4162
    "Modified: / 3.5.1999 / 08:06:28 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4163
    "Modified: / 8.5.1999 / 18:37:11 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4164
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4165
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4166
absLessEq:aLargeInteger
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4167
    "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
  4168
     This handles unnormalized largeIntegers."
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4169
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4170
    |myLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4171
     otherLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4172
     d1   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4173
     d2   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4174
     otherDigitByteArray |
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4175
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4176
%{  /* NOCONTEXT */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4177
#if defined(__LSBFIRST__)
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4178
    if (__isByteArray(__INST(digitByteArray))
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4179
     && __isLargeInteger(aLargeInteger)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4180
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4181
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4182
	if (__isByteArray(_otherDigitByteArray)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4183
	    unsigned char *_myDigits = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4184
	    unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4185
	    INT _myLen = __byteArraySize(__INST(digitByteArray));
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
	    if (_myLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4188
		INT _otherLen = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4189
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4190
		if (_otherLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4191
		    unsigned INT _myVal = *((unsigned INT *)_myDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4192
		    unsigned INT _otherVal = *((unsigned INT *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4193
		    RETURN( (_myVal <= _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4194
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4195
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4196
# if defined(UINT64) && (__POINTER_SIZE__ != 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4197
	    if (_myLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4198
		INT _otherLen = __byteArraySize(_otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4199
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4200
		if (_otherLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4201
		    UINT64 _myVal = (UINT64)(*((UINT *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4202
		    UINT64 _otherVal = *((UINT64 *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4203
		    RETURN( (_myVal <= _otherVal) ? true : false );
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
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4206
		if (_myLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4207
		    INT _otherLen = __byteArraySize(_otherDigitByteArray);
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
		    if (_otherLen <= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4210
			UINT64 _myVal = (*((UINT64 *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4211
			UINT64 _otherVal = *((UINT64 *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4212
			RETURN( (_myVal <= _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4213
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4214
		    if (_otherLen == __POINTER_SIZE__) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4215
			UINT64 _myVal = (*((UINT64 *)_myDigits));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4216
			UINT64 _otherVal = (UINT64) *((UINT *)_otherDigits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4217
			RETURN( (_myVal <= _otherVal) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4218
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4219
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4220
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4221
# endif /* UINT64 */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4222
	}
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4223
    }
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4224
#endif /* LSBFIRST */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4225
%}.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  4226
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4227
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4228
    otherDigitByteArray := aLargeInteger digitBytes.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4229
    otherLen := otherDigitByteArray size.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4230
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4231
    "/ the highest digit(s) should not be zero
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4232
    "/ when properly normalized;
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4233
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4234
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4235
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4236
    [(digitByteArray basicAt:myLen) == 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4237
	myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4238
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4239
    [(otherDigitByteArray basicAt:otherLen) == 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4240
	otherLen := otherLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4241
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4242
    (myLen < otherLen) ifTrue:[^ true].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4243
    (myLen > otherLen) ifTrue:[^ false].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4244
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4245
    [myLen > 0] whileTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4246
	d1 := digitByteArray basicAt:myLen.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4247
	d2 := otherDigitByteArray basicAt:myLen.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4248
	d1 == d2 ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4249
	    (d1 < d2) ifTrue:[^ true].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4250
	    ^ false.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4251
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4252
	myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4253
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4254
    ^ true
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4255
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4256
    "Created: / 13.2.1998 / 12:19:45 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4257
    "Modified: / 30.4.1999 / 12:46:31 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  4258
    "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
  4259
!
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  4260
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4261
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
  4262
    "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
  4263
     with sign: newSign.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4264
     The result is normalized. The argument must be a largeInteger
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4265
     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
  4266
     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
  4267
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4268
    |result done
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4269
     otherDigitByteArray resultDigitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4270
     len1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4271
     len2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4272
     index  "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4273
     borrow "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4274
     diff   "{ Class: SmallInteger }"
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4275
     carry  "{ Class: SmallInteger }"
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4276
     lastDigit
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4277
     lResult ok|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4278
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4279
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4280
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4281
    len2 := otherDigitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4282
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  4283
    len1 > len2 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4284
	lResult := len1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  4285
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4286
	lResult := (len1 max: len2) + 1.
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  4287
    ].
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  4288
    result := self class basicNew numberOfDigits:lResult sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4289
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4290
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  4291
    lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  4292
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4293
%{
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4294
    OBJ _digitByteArray = __INST(digitByteArray);
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4295
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4296
    if (__isByteArray(_digitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4297
     && __isByteArray(otherDigitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4298
     && __isByteArray(resultDigitByteArray)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4299
	int __len1 = __intVal(len1);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4300
	int __len2 = __intVal(len2);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4301
	int __minLen = __len1 < __len2 ? __len1 : __len2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4302
	int __index, __borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4303
	INT __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4304
	unsigned char *__myDigits, *__otherDigits, *__resultDigits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4305
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4306
	ok = true;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4307
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4308
	__resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4309
	__otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4310
	__myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4311
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4312
	__index = 1;
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  4313
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4314
#if defined(__LSBFIRST__)
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4315
# if __POINTER_SIZE__ == 8
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4316
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4317
	 * subtract int-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4318
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4319
	while ((__index+3) <= __minLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4320
	    /* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4321
	    __diff = ((unsigned int *)(__myDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4322
	    __diff -= ((unsigned int *)(__otherDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4323
	    __diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4324
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4325
	    if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4326
		__borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4327
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4328
		__borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4329
		/* __diff += 0x10000; */
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
	    ((unsigned int *)(__resultDigits+__index-1))[0] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4332
	    __index += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4333
	}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4334
# endif /* 64bit */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4335
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4336
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4337
	 * subtract short-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4338
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4339
	while (__index < __minLen) {   /* i.e. index+1 <= minLen */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4340
	    /* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4341
	    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4342
	    __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4343
	    __diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4344
	    if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4345
		__borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4346
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4347
		__borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4348
		/* __diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4349
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4350
	    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4351
	    __index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4352
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4353
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4354
	if (__index == __minLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4355
	    /* one of the operands has odd length - cannot continue short-wise */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4356
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4357
	    if (__len1 > __len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4358
		while (__index < __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4359
		    /* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4360
		    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4361
		    __diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4362
		    if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4363
			__borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4364
			((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4365
			__index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4366
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4367
			/* copy over rest */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4368
			while (__index < __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4369
			    ((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
  4370
			    __index+=2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4371
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4372
			if (__index <= __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4373
			    __resultDigits[__index-1] = __myDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4374
			    __index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4375
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4376
			break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4377
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4378
		    __borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4379
		    /* __diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4380
		    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4381
		    __index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4382
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4383
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4384
		if (__len2 > __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4385
		    while (__index < __len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4386
			/* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4387
			__diff = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4388
			__diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4389
			__diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4390
			if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4391
			    __borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4392
			} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4393
			    __borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4394
			    /* __diff += 0x10000; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4395
			}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4396
			((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4397
			__index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4398
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4399
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4400
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4401
	}
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  4402
#endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4403
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4404
	 * subtract byte-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4405
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4406
	while (__index <= __minLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4407
	    /* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4408
	    __diff = __myDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4409
	    __diff -= __otherDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4410
	    __diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4411
	    if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4412
		__borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4413
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4414
		__borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4415
		/* __diff += 0x100; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4416
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4417
	    __resultDigits[__index-1] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4418
	    __index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4419
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4420
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4421
	if (__len1 > __len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4422
	    while (__index <= __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4423
		/* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4424
		__diff = __myDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4425
		__diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4426
		if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4427
		    __borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4428
		    /* copy over rest */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4429
		    __resultDigits[__index-1] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4430
		    __index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4431
		    while (__index <= __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4432
			__resultDigits[__index-1] = __myDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4433
			__index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4434
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4435
		    break;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4436
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4437
		__borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4438
		/* __diff += 0x100; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4439
		__resultDigits[__index-1] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4440
		__index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4441
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4442
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4443
	    if (__len2 > __len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4444
		while (__index <= __len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4445
		    /* do not make this into one expression - ask cg why */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4446
		    __diff = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4447
		    __diff -= __otherDigits[__index-1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4448
		    __diff -= __borrow;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4449
		    if (__diff >= 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4450
			__borrow = 0;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4451
		    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4452
			__borrow = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4453
			/* __diff += 0x100; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4454
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4455
		    __resultDigits[__index-1] = __diff;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4456
		    __index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4457
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4458
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4459
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4460
	borrow = __mkSmallInteger(__borrow);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4461
	index = __mkSmallInteger(__index);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4462
	lastDigit = __mkSmallInteger(__resultDigits[__intVal(lResult)-1]);
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4463
    }
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4464
%}.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4465
    ok == true ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4466
	index := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4467
	borrow := 0.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4468
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4469
	done := false.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4470
	[done] whileFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4471
	    diff := borrow.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4472
	    (index <= len1) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4473
		diff := diff + (digitByteArray basicAt:index).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4474
		(index <= len2) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4475
		    diff := diff - (otherDigitByteArray basicAt:index)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4476
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4477
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4478
		(index <= len2) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4479
		    diff := diff - (otherDigitByteArray basicAt:index)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4480
		] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4481
		    "end reached"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4482
		    done := true
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4483
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4484
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4485
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4486
	    "/ workaround for
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4487
	    "/ gcc code generator bug
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4488
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4489
	    (diff >= 0) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4490
		borrow := 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4491
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4492
		borrow := -1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4493
		diff := diff + 16r100
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4494
	    ].
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4495
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4496
    "/        (diff < 0) ifTrue:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4497
    "/            borrow := -1.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4498
    "/            diff := diff + 16r100
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4499
    "/        ] ifFalse:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4500
    "/            borrow := 0
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4501
    "/        ].
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  4502
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4503
	    resultDigitByteArray basicAt:index put:diff.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4504
	    index := index + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4505
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4506
	lastDigit := resultDigitByteArray basicAt:lResult.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4507
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  4508
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4509
    (borrow ~~ 0) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4510
	"/ must generate 255's complement
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4511
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4512
	result sign:newSign negated.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4513
	[index <= lResult] whileTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4514
	    resultDigitByteArray basicAt:index put:16rFF.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4515
	    index := index + 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4516
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4517
	index := lResult.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4518
	[index > 0] whileTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4519
	    resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4520
	    index := index - 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4521
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4522
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4523
	index := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4524
	carry := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4525
	[carry ~~ 0] whileTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4526
	    (index <= lResult) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4527
		carry := (resultDigitByteArray basicAt:index) + carry.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4528
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4529
	    resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4530
	    carry := carry bitShift:-8.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4531
	    index := index + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4532
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4533
	lastDigit := resultDigitByteArray basicAt:lResult.
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  4534
    ].
15242
4539185c87ed class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15240
diff changeset
  4535
    (lastDigit == 0 or:[lResult <= SmallInteger maxBytes]) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4536
	^ result compressed.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4537
    ].
15242
4539185c87ed class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15240
diff changeset
  4538
    ^ result
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  4539
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  4540
    "Modified: 5.11.1996 / 14:09:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4541
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4542
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4543
absMod:anInteger
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4544
    "return the remainder from the expression:
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4545
         abs(self) \\ abs(theArgument).
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4546
     Used as a helper for \\ and rem:"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4547
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4548
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4549
    |dividend divisor
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4550
     modOrNil    
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4551
     shift "{ Class: SmallInteger }" |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4552
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4553
    anInteger == 0 ifTrue:[
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4554
        ^ ZeroDivide raiseRequestWith:thisContext
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4555
    ].
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4556
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4557
    anInteger class == SmallInteger ifTrue:[
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4558
        divisor := anInteger abs.
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4559
        modOrNil := self absFastMod:divisor.
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4560
        modOrNil notNil ifTrue:[^ modOrNil].
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4561
        divisor := divisor asLargeInteger.
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4562
    ] ifFalse:[
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4563
        divisor := anInteger.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4564
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4565
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4566
    self = anInteger ifTrue:[
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4567
        ^ 0
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4568
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4569
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4570
    shift := self highBit - divisor highBit.
16124
23f576b31095 class: LargeInteger
Stefan Vogel <sv@exept.de>
parents: 15909
diff changeset
  4571
    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
  4572
    shift < 0 ifTrue:[
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4573
        ^ dividend compressed.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4574
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  4575
    shift == 0 ifTrue:[
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4576
        divisor := self class digitBytes:(divisor digitBytes copy). "/ anInteger simpleDeepCopy
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  4577
    ] ifFalse:[
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4578
        divisor := divisor bitShift:shift.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4579
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4580
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4581
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4582
    [shift > 0] whileTrue:[
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4583
        (dividend absLess:divisor) ifFalse:[
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4584
            (dividend absDestructiveSubtract: divisor) ifFalse:[ "result == 0"
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4585
                ^ 0
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4586
            ].
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4587
        ].
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4588
        shift := shift - 1.
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4589
        divisor div2.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4590
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4591
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4592
    ^ dividend compressed
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4593
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4594
    "
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4595
Time millisecondsToRun:[   100000 timesRepeat:[  16000000000000000000001 absDivMod:4000000000000000000001] ]
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4596
Time millisecondsToRun:[   100000 timesRepeat:[  16000000000000000000001 absMod:4000000000000000000001] ]
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4597
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4598
     16000000000 absMod:4000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4599
     16000000000 absMod:3000000000
19126
98adb7dc1950 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19102
diff changeset
  4600
     16000000000000000000 absMod:16000000000000000000
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4601
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4602
21985
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4603
    "Created: / 27-04-1999 / 19:45:44 / stefan"
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4604
    "Modified: / 26-07-1999 / 10:46:18 / stefan"
bc1731b1a6aa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21820
diff changeset
  4605
    "Modified: / 05-07-2017 / 16:17:47 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4606
!
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4607
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4608
absMul:aLargeInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4609
    "return a LargeInteger representing abs(self) * abs(theArgument)"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4610
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4611
    |result otherDigitByteArray resultDigitByteArray ok
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4612
     idx      "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4613
     carry    "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4614
     len1     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4615
     len2     "{ Class: SmallInteger }"
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4616
     lenRslt  "{ Class: SmallInteger }"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4617
     dstIndex "{ Class: SmallInteger }"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  4618
     prod     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  4619
     v        "{ Class: SmallInteger }"|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4620
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4621
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4622
    otherDigitByteArray := aLargeInteger digitBytes.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4623
    len2 := otherDigitByteArray size.
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4624
    lenRslt := len1 + len2.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4625
    UseKarazuba ~~ false ifTrue:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4626
	lenRslt > 400 ifTrue:[ ^ self absMulKarazuba:aLargeInteger ].
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4627
    ].
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4628
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4629
    result := self class basicNew numberOfDigits:lenRslt.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4630
    resultDigitByteArray := result digitBytes.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4631
    ok := false.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4632
%{
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  4633
    if (__isByteArray(__INST(digitByteArray))
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4634
     && __isByteArray(otherDigitByteArray)
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4635
     && __isByteArray(resultDigitByteArray)) {
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4636
	unsigned char *myBytes = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4637
	unsigned char *otherBytes = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4638
	unsigned char *resultBytes = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4639
	unsigned char *_p1, *_pResult0, *_p1Last, *_p2Last;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4640
	unsigned INT _v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4641
	int _len1 = __intVal(len1);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4642
	int _len2 = __intVal(len2);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4643
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4644
	_p1Last = myBytes    + _len1 - 1;  /* the last byte */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4645
	_p2Last = otherBytes + _len2 - 1;  /* the last byte */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4646
	_pResult0 = resultBytes;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4647
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4648
	/*
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4649
	 *         aaa...aaa      f1[0] * f2
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4650
	 * +      bbb...bbb       f1[1] * f2
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4651
	 * +     ccc...ccc        f1[2] * f2
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4652
	 * +    ...
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4653
	 * +   xxx...xxx          f1[high] * f2
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4654
	 *
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4655
	 * start short-wise
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4656
	 * bounds: (16rFFFF * 16rFFFF) + 16rFFFF -> FFFF0000
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4657
	 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4658
	_p1 = myBytes;
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  4659
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4660
#if defined(__LSBFIRST__) && (__POINTER_SIZE__ == 8)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4661
	/* loop over ints of f1 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4662
	for (; _p1 <= (_p1Last-3); _p1 += 4, _pResult0 += 4) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4663
	    unsigned char *_pResult = _pResult0;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4664
	    unsigned char *_p2;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4665
	    unsigned INT word1 = ((unsigned int *)_p1)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4666
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4667
	    _v = 0;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4668
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4669
	    /* loop over ints of f2 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4670
	    for (_p2 = otherBytes; _p2 <= (_p2Last-3); _p2 += 4) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4671
		_v = word1 * (unsigned INT)(((unsigned int *)_p2)[0])
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4672
		     + _v + (unsigned INT)((unsigned int *)_pResult)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4673
		((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4674
		_v >>= 32; /* now _v contains the carry*/
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4675
		_pResult += 4;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4676
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4677
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4678
	    /* possible odd up to 3 highBytes of f2 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4679
	    for ( ; _p2 <= _p2Last; _p2++) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4680
		_v = word1 * (unsigned INT)(_p2[0])
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4681
		     + _v + (unsigned INT)(_pResult[0]);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4682
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4683
		((unsigned char *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4684
		_v >>= 8; /* now _v contains the carry*/
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4685
		_pResult++;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4686
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4687
	    /* distribute leftover carry byte-wise */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4688
	    for ( ; _v; _v >>= 8, _pResult++) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4689
		_v += _pResult[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4690
		_pResult[0] = _v /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4691
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4692
	}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4693
#endif /* 64bit */
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4694
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4695
	/* possible odd high short of f1 (or shortLoop, if not 64bit) */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4696
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4697
	for (; _p1 < _p1Last; _p1 += 2, _pResult0 += 2) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4698
	    unsigned char *_pResult = _pResult0;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4699
	    unsigned char *_p2 = otherBytes;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4700
	    unsigned int short1 = ((unsigned short *)_p1)[0];
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  4701
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4702
#if !defined(__LSBFIRST__)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4703
	    short1 = ((short1 >> 8) & 0xFF) | ((short1 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  4704
#endif
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4705
	    _v = 0;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4706
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4707
	    /* loop over shorts of f2 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4708
	    for ( ; _p2 < _p2Last; _p2 += 2, _pResult += 2) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4709
#if !defined(__LSBFIRST__)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4710
		unsigned int _short2  = ((unsigned short *)_p2)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4711
		unsigned int _short3  = ((unsigned short *)_pResult)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4712
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4713
		_short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4714
		_short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4715
		_v = (short1 * _short2) + _short3 + _v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4716
		_pResult[0] = _v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4717
		_pResult[1] = _v >> 8;
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4718
#else /* __LSBFIRST__ */
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4719
		_v = (short1 * ((unsigned short *)_p2)[0]) + _v + ((unsigned short *)_pResult)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4720
		((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4721
#endif /* __LSBFIRST__ */
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4722
		_v >>= 16; /* now _v contains the carry*/
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4723
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4724
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4725
	    /* possible odd highByte of f2 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4726
	    for ( ; _p2 <= _p2Last; _p2++, _pResult += 2) {
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4727
#if !defined(__LSBFIRST__)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4728
		unsigned int _short3 = ((unsigned short *)_pResult)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4729
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4730
		_short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4731
		_v = (short1 * _p2[0]) + _v + _short3;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4732
		_pResult[0] = _v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4733
		_pResult[1] = _v >> 8;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4734
#else /* __LSBFIRST__ */
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4735
		_v = (short1 * _p2[0]) + _v + ((unsigned short *)_pResult)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4736
		((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4737
#endif /* __LSBFIRST__ */
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4738
		_v >>= 16; /* now _v contains the carry*/
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4739
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4740
	    /* distribute leftover carry byte-wise */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4741
	    for ( ; _v; _v >>= 8, _pResult++) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4742
		_v += _pResult[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4743
		_pResult[0] = _v /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4744
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4745
	}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4746
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4747
	/* possible odd highByte of f1 (or byteLoop, if above is ever disabled) */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4748
	for (; _p1 <= _p1Last; _p1++, _pResult0++) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4749
	    unsigned char *_pResult = _pResult0;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4750
	    unsigned char *_p2 = otherBytes;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4751
	    unsigned int byte1 = _p1[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4752
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4753
	    _v = 0;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4754
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4755
	    /* loop over shorts of f2 */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4756
	    for ( ; _p2 < _p2Last; _p2 += 2, _pResult += 2) {
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4757
#if !defined(__LSBFIRST__)
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4758
		unsigned int _short2 = ((unsigned short *)_p2)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4759
		unsigned int _short3  = ((unsigned short *)_pResult)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4760
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4761
		_short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4762
		_short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4763
		_v = (byte1 * _short2) + _v +_short3;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4764
		_pResult[0] = _v;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4765
		_pResult[1] = _v >> 8;
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4766
#else /* __LSBFIRST__ */
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4767
		_v = (byte1 * ((unsigned short *)_p2)[0]) + _v + ((unsigned short *)_pResult)[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4768
		((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
19870
94851a6996a4 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19864
diff changeset
  4769
#endif /* __LSBFIRST__ */
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4770
		_v >>= 16; /* now _v contains the carry*/
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4771
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4772
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4773
	    /* possible odd highByte of f2 (or byteLoop, if not __LSBFIRST__) */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4774
	    for ( ; _p2 <= _p2Last; _p2++, _pResult++) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4775
		_v = (byte1 * _p2[0]) + _v + _pResult[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4776
		_pResult[0] = _v /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4777
		_v >>= 8; /* now _v contains the carry*/
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4778
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4779
	    /* distribute leftover carry byte-wise */
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4780
	    for ( ; _v; _v >>= 8, _pResult++) {
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4781
		_v += _pResult[0];
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4782
		_pResult[0] = _v /* & 0xFF */;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4783
	    }
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4784
	}
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4785
	ok = true;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4786
    }
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4787
%}.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4788
    ok ifFalse:[
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4789
	1 to:len1 do:[:index1 |
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4790
	    1 to:len2 do:[:index2 |
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4791
		dstIndex := index1 + index2 - 1.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4792
		prod := (digitByteArray basicAt:index1) * (otherDigitByteArray basicAt:index2).
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4793
		prod := prod + (resultDigitByteArray basicAt:dstIndex).
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4794
		resultDigitByteArray basicAt:dstIndex put:(prod bitAnd:16rFF).
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4795
		carry := prod bitShift:-8.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4796
		carry ~~ 0 ifTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4797
		    idx := dstIndex + 1.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4798
		    [carry ~~ 0] whileTrue:[
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4799
			v := (resultDigitByteArray basicAt:idx) + carry.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4800
			resultDigitByteArray basicAt:idx put:(v bitAnd:255).
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4801
			carry := v bitShift:-8.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4802
			idx := idx + 1
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4803
		    ]
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4804
		]
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4805
	    ]
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4806
	].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4807
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  4808
    ^ result compressed
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4809
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4810
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4811
absMulKarazuba:aLargeInteger
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4812
    "return a LargeInteger representing abs(self) * abs(theArgument) using the karazuba algorithm.
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4813
	a = (2^n * p) + q
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4814
	b = (2^n * r) + s
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4815
	a * b   = ((2^n * p) + q) * ((2^n * r) + s)
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4816
		= 2^(n+n)*p*r + 2^n*p*s + 2^n*q*r + q*s
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4817
		= 2^(n+n)*p*r + (p*r + q*s - (q-p)*(s-r))*2^n + q*s
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4818
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4819
	this is faster for sufficient large n1,n2
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4820
	because regular multiplication is O(n1*n2) and karazuma multiplies much smaller numbers
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4821
	(half number of bits) but does more multiplications (on smaller numbers) and req's more
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4822
	additions and subtractions (on smaller numbers).
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4823
	The break-even for when to use regular multiplication has been determined heuristically
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4824
	and is somewhere around 1600 bits (digitLength of 200).
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4825
	(see test in absMul:)
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4826
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4827
	To disable karazuba, set UseKarazuba to false.
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4828
    "
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4829
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4830
    "/ compute half-sized pi and qi...
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4831
    |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
  4832
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4833
    l1 := self digitLength.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4834
    l2 := aLargeInteger digitLength.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4835
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4836
    n := l1 max:l2.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4837
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4838
    nh := (n / 2) ceiling. n := nh * 2.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4839
    p := LargeInteger digitBytes:(digitByteArray copyFrom:nh+1) sign:1. "/ high bits of nr1
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4840
    q := LargeInteger digitBytes:(digitByteArray copyToMax:nh) sign:1.   "/ low bits of nr1
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4841
    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
  4842
    s := LargeInteger digitBytes:(aLargeInteger digitBytes copyToMax:nh).           "/ low bits of nr2
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4843
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4844
    p := p compressed.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4845
    q := q compressed.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4846
    r := r compressed.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4847
    s := s compressed.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4848
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4849
    pr := p * r.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4850
    qs := q * s.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4851
    q_p := q - p.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4852
    s_r := s - r.
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4853
    q_ps_r := q_p * s_r.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4854
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4855
    pr_raisedTo_n := (pr bitShift:(n*8)).
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4856
    mdl_raisedTo_nh := ((pr + qs - q_ps_r) bitShift:(nh*8)).
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4857
    ^ pr_raisedTo_n + mdl_raisedTo_nh + qs
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4858
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4859
    "
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4860
     #(100 500 1000 2500 5000 10000 25000 50000 100000 250000 500000 1000000) do:[:exp |
20418
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4861
	 |nr r1 r2|
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4862
	 nr := (3 raisedTo:exp) asInteger.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4863
	 Transcript show:exp; show:' nbytes: '; showCR:nr digitLength;
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4864
	    show:'  normal: '; show:(Time microsecondsToRun:[ UseKarazuba := false. r1 := nr * nr ]); showCR:'us';
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4865
	    show:'  karazuba: '; show:(Time microsecondsToRun:[ UseKarazuba := true. r2 := nr absMulKarazuba: nr]); showCR:'us'.
f0d4c001928b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20340
diff changeset
  4866
	 self assert:(r1 = r2).
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4867
     ]
18847
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4868
    "
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4869
!
bb459d34d125 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18845
diff changeset
  4870
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4871
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
  4872
    "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
  4873
     with sign: newSign.
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4874
     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
  4875
     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
  4876
     This is a helper for addition and subtraction - not for public use."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4877
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4878
    |result done otherDigitByteArray resultDigitByteArray
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4879
     len1   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4880
     len2   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4881
     newLen "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4882
     index  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4883
     carry  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4884
     sum    "{ Class: SmallInteger }" |
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4885
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4886
    otherDigitByteArray := aLargeInteger digitBytes.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4887
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4888
%{
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4889
    OBJ _digitByteArray = __INST(digitByteArray);
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4890
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4891
    if (__isByteArray(_digitByteArray)
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4892
     && __isByteArray(otherDigitByteArray)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4893
	int _len1, _len2, _newLen;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4894
	unsigned char *_myDigits, *_otherDigits, *_newDigits;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4895
	int _index, _carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4896
	int _comLen;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4897
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4898
	_len1 = __byteArraySize(_digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4899
	_len2 = __byteArraySize(otherDigitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4900
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4901
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4902
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4903
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4904
	if (_len1 < _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4905
	    _comLen = _len1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4906
	    _newLen = _len2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4907
	    if (_otherDigits[_len2 - 1] == 0xFF) _newLen++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4908
	} else if (_len2 < _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4909
	    _comLen = _len2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4910
	    _newLen = _len1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4911
	    if (_myDigits[_len1 - 1] == 0xFF) _newLen++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4912
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4913
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4914
	     * there can only be an overflow from the high bytes,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4915
	     * if their sum is >= 255
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4916
	     * (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
  4917
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4918
	    _newLen = _len1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4919
	    if ((_otherDigits[_len2 - 1] + _myDigits[_len1 - 1]) >= 0xFF) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4920
		_newLen++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4921
	    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4922
		if (_newLen == sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4923
		    OBJ _uint;
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
		    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4926
		     * two word-sized numbers, no carry - a very common case ...
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4927
		     */
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  4928
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4929
		    unsigned INT _sum = *(unsigned INT *)_otherDigits + *(unsigned INT *)_myDigits;
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  4930
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4931
		    unsigned INT _sum = __unsignedLongIntVal(self) + __unsignedLongIntVal(aLargeInteger);
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  4932
#endif /* not LSB_FIRST */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4933
		    if (_sum <= _MAX_INT) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4934
			_uint = __mkSmallInteger(_sum * __intVal(newSign));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4935
		    } else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4936
			_uint = __MKULARGEINT(_sum);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4937
			__LargeIntegerInstPtr(_uint)->l_sign = newSign;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4938
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4939
		    RETURN (_uint);
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
	    _comLen = _len1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4943
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4944
	resultDigitByteArray = __BYTEARRAY_UNINITIALIZED_NEW_INT(_newLen);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4945
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4946
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4947
	 * must refetch - GC could have been invoked
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
	_digitByteArray = __INST(digitByteArray);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4950
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4951
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4952
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4953
	_newDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
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
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4956
	 * add them ...
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4957
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4958
	_index = 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4959
	_carry = 0;
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  4960
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4961
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4962
# if (__POINTER_SIZE__ == 8) && defined(__GNUC__) && defined(__alpha__)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4963
#  if 0  /* not faster (on alpha) */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4964
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4965
	    int _comLen7;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4966
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4967
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4968
	     * have a 64bit integers;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4969
	     * add quad-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4970
	     * accessing bytes at: [index-1][index][index+1]..[index+6]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4971
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4972
	    _comLen7 = _comLen - 3 - 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4973
	    while (_index <= _comLen7) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4974
		UINT64 _sum, _t1, _t2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4975
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4976
		asm ("addq   %5,%6,%1         /* sum */                  \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4977
		      addq   %0,%1,%1         /* plus carryIn */         \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4978
		      cmpult %1,%5,%2         /* was there a carry ? */  \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4979
		      cmpult %1,%6,%3         /* was there a carry ? */  \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4980
		      bis    %2,%3,%0         /* carryOut */             \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4981
		     "
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4982
			: "=r"  (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4983
			  "=r"  (_sum),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4984
			  "r"   (_t1),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4985
			  "r"   (_t2)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4986
			: "r"   (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4987
			  "r"   (((unsigned long *)(&(_myDigits[_index - 1])))[0]),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4988
			  "r"   (((unsigned long *)(&(_otherDigits[_index - 1])))[0])
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
		/* _sum = _sum & 0xFFFFFFFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4991
		((unsigned long *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4992
		_index += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4993
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  4994
	}
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  4995
#  endif / notdef */
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  4996
# endif /* 64bit alpha */
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4997
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4998
# if (__POINTER_SIZE__ == 8)
19157
5543dd7af087 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19135
diff changeset
  4999
# if 0  /* not faster */
19262
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
	    int _comLen7;
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
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5004
	     * have a 64bit integers;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5005
	     * add quad-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5006
	     * accessing bytes at: [index-1][index][index+1]..[index+6]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5007
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5008
	    _comLen7 = _comLen - 3 - 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5009
	    while (_index <= _comLen7) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5010
		UINT64 _sum, _t1, _t2;
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
		_t1 = ((UINT64 *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5013
		_t2 = ((UINT64 *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5014
		_sum = _t1 + _t2 + _carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5015
		((UINT64 *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5016
		_carry = (_sum < _t1) | (_sum < _t2);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5017
		_index += 8;
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
	}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  5020
#  endif
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  5021
# endif /* 64bit */
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  5022
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  5023
# ifdef UINT64
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5024
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5025
	    int _comLen3;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5026
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5027
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5028
	     * have a 64bit integer type;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5029
	     * add int-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5030
	     * accessing bytes at: [index-1][index][index+1][index+2]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5031
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5032
	    _comLen3 = _comLen - 3;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5033
	    while (_index <= _comLen3) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5034
		UINT64 _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5035
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5036
		/* do not merge the 3 lines below into one -
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5037
		 * (will do sign extension then, which is wrong here)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5038
		 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5039
		_sum = (unsigned)_carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5040
		_sum += ((unsigned int *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5041
		_sum += ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5042
		_carry = _sum >> 32;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5043
		/* _sum = _sum & 0xFFFFFFFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5044
		((unsigned int *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5045
		_index += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5046
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5047
	}
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  5048
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  5049
#  if defined(__i386__) && defined(__GNUC__) && (__POINTER_SIZE__ == 4)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5050
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5051
	    int _comLen3;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5052
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5053
	    _comLen3 = _comLen - 3 - 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5054
	    while (_index <= _comLen3) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5055
		unsigned int _sum, _sum2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5056
		unsigned int __in1A, __in1B, __in2A, __in2B;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5057
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5058
		__in1A = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5059
		__in2A = ((unsigned int *)(&(_myDigits[_index - 1])))[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5060
		__in1B = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5061
		__in2B = ((unsigned int *)(&(_otherDigits[_index - 1])))[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5062
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5063
		asm ("addl %%edx,%%eax  \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5064
		      movl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5065
		      adcl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5066
		      addl %5,%%eax     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5067
		      adcl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5068
					\n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5069
		      addl %%edx,%%ecx  \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5070
		      movl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5071
		      adcl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5072
		      addl %7,%%ecx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5073
		      adcl $0,%%edx     \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5074
		     "
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5075
			: "=d"  (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5076
			  "=a"  (_sum),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5077
			  "=c"  (_sum2)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5078
			: "0"   (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5079
			  "1"   (__in1A),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5080
			  "rm"  (__in1B),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5081
			  "2"   (__in2A),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5082
			  "rm"  (__in2B)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5083
		    );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5084
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5085
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5086
		((unsigned *)(&(_newDigits[_index - 1])))[1] = _sum2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5087
		_index += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5088
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5089
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5090
	     * add int-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5091
	     * accessing bytes at: [index-1][index][index+1][index+2]
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
	    _comLen3 = _comLen3 + 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5094
	    if (_index <= _comLen3) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5095
		unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5096
		unsigned int __inA, __inB;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5097
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5098
		__inA = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5099
		__inB = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
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
		asm ("addl %%edx,%%eax      \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5102
		      movl $0,%%edx         \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5103
		      adcl $0,%%edx         \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5104
		      addl %4,%%eax         \n\
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5105
		      adcl $0,%%edx"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5106
			: "=d"  (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5107
			  "=a"  (_sum)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5108
			: "0"   (_carry),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5109
			  "1"   (__inA),
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5110
			  "rm"  (__inB)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5111
		    );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5112
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5113
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5114
		_index += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5115
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5116
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  5117
#  endif /* __i386__ && GNUC */
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  5118
#  if defined(__win32__) && defined(__BORLANDC__) && defined(__x86__) && (__POINTER_SIZE__ == 4)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5119
	{
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5120
	    int _comLen3;
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
	    /*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5123
	     * add long-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5124
	     * accessing bytes at: [index-1][index][index+1][index+2]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5125
	     */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5126
	    _comLen3 = _comLen - 3;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5127
	    while (_index <= _comLen3) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5128
		unsigned int _sum, _v1, _v2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5129
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5130
		_v1 = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5131
		_v2 = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5132
		asm {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5133
		      mov eax, _v1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5134
		      add eax, _v2
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5135
		      mov edx, 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5136
		      adc edx, 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5137
		      add eax, _carry
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5138
		      adc edx, 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5139
		      mov _carry, edx
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5140
		      mov _sum, eax
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5141
		    }
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
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5144
		_index += 4;
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
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  5147
#  endif /* __i386__ && WIN32 */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  5148
# endif /* INT64 */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5149
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5150
	 * add short-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5151
	 * accessing bytes at: [index-1][index]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5152
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5153
	while (_index < _comLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5154
	    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5155
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5156
	    _sum = _carry
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5157
		   + ((unsigned short *)(&(_myDigits[_index - 1])))[0]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5158
		   + ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5159
	    _carry = _sum >> 16;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5160
	    /* _sum = _sum & 0xFFFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5161
	    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5162
	    _index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5163
	}
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  5164
#else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  5165
# ifdef __sparc__
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5166
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5167
	 * add short-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5168
	 * accessing bytes at: [index-1][index]
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
	while (_index < _comLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5171
	    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5172
	    unsigned short _v1, _v2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5173
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5174
	    _v1 = ((unsigned short *)(&(_myDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5175
	    _v2 = ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5176
	    _sum = _carry + (_v1>>8) + (_v2>>8);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5177
	    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5178
	    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5179
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5180
	    _sum = _carry + (_v1 & 0xFF) + (_v2 & 0xFF);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5181
	    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5182
	    _newDigits[_index] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5183
	    _index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5184
	}
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  5185
# endif
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  5186
#endif /* __LSBFIRST__ */
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  5187
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5188
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5189
	 * add byte-wise
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5190
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5191
	while (_index <= _comLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5192
	    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5193
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5194
	    _sum = _carry
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5195
		   + _myDigits[_index - 1]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5196
		   + _otherDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5197
	    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5198
	    /* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5199
	    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5200
	    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5201
	}
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
	/*
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5204
	 * rest
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5205
	 */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5206
	if (_len1 > _len2) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  5207
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5208
	    if (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5209
		if ((_index - 1) & 1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5210
		    /* odd byte */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5211
		    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5212
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5213
		    _sum = _carry + _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5214
		    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5215
		    /* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5216
		    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5217
		    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5218
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5219
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5220
		while (_index < _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5221
		    /* shorts */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5222
		    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5223
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5224
		    _sum = _carry + *(unsigned short *)(&(_myDigits[_index - 1]));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5225
		    _carry = _sum >> 16;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5226
		    /* _sum = _sum & 0xFFFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5227
		    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5228
		    _index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5229
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5230
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5231
		if (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5232
		    /* last byte */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5233
		    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5234
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5235
		    _sum = _carry + _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5236
		    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5237
		    /* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5238
		    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5239
		    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5240
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5241
	    }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  5242
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5243
	    while (_index <= _len1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5244
		unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5245
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5246
		_sum = _carry + _myDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5247
		_carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5248
		/* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5249
		_newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5250
		_index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5251
	    }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  5252
#endif /* not LSB */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5253
	} else {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5254
	    if (_len2 > _len1) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  5255
#if defined(__LSBFIRST__)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5256
		if (_index <= _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5257
		    if ((_index - 1) & 1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5258
			/* odd byte */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5259
			unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5260
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5261
			_sum = _carry + _otherDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5262
			_carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5263
			/* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5264
			_newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5265
			_index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5266
		    }
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
		    while (_index < _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5269
			/* shorts */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5270
			unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5271
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5272
			_sum = _carry + *(unsigned short *)(&(_otherDigits[_index - 1]));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5273
			_carry = _sum >> 16;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5274
			/* _sum = _sum & 0xFFFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5275
			*(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5276
			_index += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5277
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5278
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5279
		    if (_index <= _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5280
			/* last byte */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5281
			unsigned int _sum;
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
			_sum = _carry + _otherDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5284
			_carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5285
			/* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5286
			_newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5287
			_index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5288
		    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5289
		}
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  5290
#else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5291
		while (_index <= _len2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5292
		    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5293
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5294
		    _sum = _carry + _otherDigits[_index - 1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5295
		    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5296
		    /* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5297
		    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5298
		    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5299
		}
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  5300
#endif /* not LSB */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5301
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5302
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5303
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5304
	while (_index <= _newLen) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5305
	    unsigned int _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5306
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5307
	    _sum = _carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5308
	    _carry = _sum >> 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5309
	    /* _sum = _sum & 0xFF; */
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5310
	    _newDigits[_index - 1] = _sum;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5311
	    _index++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5312
	}
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5313
    }
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5314
%}.
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5315
    resultDigitByteArray notNil ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5316
	result := self class basicNew.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5317
	result setDigits:resultDigitByteArray.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5318
	result setSign:newSign.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5319
    ] ifFalse:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5320
	len1 := digitByteArray size.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5321
	len2 := otherDigitByteArray size.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5322
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5323
	"/ earlier versions estimated the newLength as:
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5324
	"/ (len1 max:len2) + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5325
	"/ and reduced the result.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5326
	"/ however, if one of the addends is smaller,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5327
	"/ the result will never require another digit,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5328
	"/ if the highest digit of the larger addent is
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5329
	"/ not equal to 255. Therefore, in most cases,
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5330
	"/ we can avoid the computation and resizing
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5331
	"/ in #reduced.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5332
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5333
	len1 < len2 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5334
	    newLen := len2.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5335
	    (otherDigitByteArray at:len2) == 16rFF ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5336
		newLen := newLen + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5337
	    ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5338
	] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5339
	    len2 < len1 ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5340
		newLen := len1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5341
		(digitByteArray at:len1) == 16rFF ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5342
		    newLen := newLen + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5343
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5344
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5345
		newLen := len1 + 1.
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
	].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5348
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5349
	result := self class basicNew numberOfDigits:newLen.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5350
	result sign:newSign.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5351
	resultDigitByteArray := result digitBytes.
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
	index := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5354
	carry := 0.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5355
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5356
	done := false.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5357
	[done] whileFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5358
	    sum := carry.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5359
	    (index <= len1) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5360
		sum := sum + (digitByteArray basicAt:index).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5361
		(index <= len2) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5362
		    sum := sum + (otherDigitByteArray basicAt:index)
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
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5365
		(index <= len2) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5366
		    sum := sum + (otherDigitByteArray basicAt:index)
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5367
		] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5368
		    "end reached"
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5369
		    done := true
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5370
		]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5371
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5372
	    (sum >= 16r100) ifTrue:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5373
		carry := 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5374
		sum := sum - 16r100
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5375
	    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5376
		carry := 0
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5377
	    ].
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5378
	    resultDigitByteArray basicAt:index put:sum.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5379
	    index := index + 1
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5380
	].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5381
    ].
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5382
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  5383
    ^ result compressed
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  5384
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  5385
    "Modified: 11.8.1997 / 03:23:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5386
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5387
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5388
div2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5389
    "private helper for division:
15326
7cc303092044 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15312
diff changeset
  5390
       destructively divide the receiver by 2.
7cc303092044 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15312
diff changeset
  5391
       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
  5392
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5393
    |prevBit|
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5394
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5395
%{  /* NOCONTEXT */
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5396
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5397
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5398
    if (__isByteArray(__digits)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5399
	int __nBytes = __byteArraySize(__digits);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5400
	unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5401
	unsigned INT __this, __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5402
	int __idx;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5403
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5404
	if (__nBytes == 1) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5405
	    __bp[0] >>= 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5406
	    RETURN (self);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5407
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5408
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5409
	__idx = 1;
16916
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  5410
62312c3220bf class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 16520
diff changeset
  5411
#if defined(__LSBFIRST__)
15326
7cc303092044 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15312
diff changeset
  5412
# if (__POINTER_SIZE__ == 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5413
	if (sizeof(unsigned INT) == 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5414
	    int __endIndex = __nBytes - 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5415
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5416
	    if (__idx < __endIndex) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5417
		__this = ((unsigned INT *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5418
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5419
		while (__idx < __endIndex) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5420
		    __next = ((unsigned INT *)__bp)[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5421
		    __this = (__this >> 1) /* & 0x7FFFFFFFFFFFFFF */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5422
		    __this |= __next << 63;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5423
		    ((unsigned INT *)__bp)[0] = __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5424
		    __this = __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5425
		    __bp += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5426
		    __idx += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5427
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5428
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5429
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5430
	    if (__idx < (__nBytes - 4)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5431
		__this = ((unsigned int *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5432
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5433
		__next = ((unsigned int *)__bp)[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5434
		__this = (__this >> 1) /* & 0x7FFFFFF */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5435
		__this |= __next << 31;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5436
		((unsigned int *)__bp)[0] = __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5437
		__this = __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5438
		__bp += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5439
		__idx += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5440
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5441
	    if (__idx < (__nBytes - 2)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5442
		__this = ((unsigned short *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5443
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5444
		__next = ((unsigned short *)__bp)[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5445
		__this = (__this >> 1) /* & 0x7FFFFFF */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5446
		__this |= __next << 15;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5447
		((unsigned short *)__bp)[0] = __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5448
		__this = __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5449
		__bp += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5450
		__idx += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5451
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5452
	}
15326
7cc303092044 class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 15312
diff changeset
  5453
# else
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5454
	if (sizeof(unsigned int) == 4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5455
	    int __endIndex = __nBytes - 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5456
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5457
	    if (__idx < __endIndex) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5458
		__this = ((unsigned int *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5459
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5460
		while (__idx < __endIndex) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5461
		    __next = ((unsigned int *)__bp)[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5462
		    __this = (__this >> 1) /* & 0x7FFFFFF */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5463
		    __this |= __next << 31;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5464
		    ((unsigned int *)__bp)[0] = __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5465
		    __this = __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5466
		    __bp += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5467
		    __idx += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5468
		}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5469
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5470
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5471
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  5472
#endif
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5473
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5474
	__this = __bp[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5475
	while (__idx < __nBytes) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5476
	    __next = __bp[1];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5477
	    __this >>= 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5478
	    __this |= __next << 7;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5479
	    __bp[0] = __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5480
	    __this = __next;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5481
	    __bp++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5482
	    __idx++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5483
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5484
	__bp[0] = __this >> 1;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5485
	RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5486
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5487
%}.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5488
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5489
    prevBit := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5490
    digitByteArray size to:1 by:-1 do:[:idx |
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5491
	|thisByte|
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5492
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5493
	thisByte := digitByteArray at:idx.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5494
	digitByteArray at:idx put:((thisByte bitShift:-1) bitOr:prevBit).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5495
	prevBit := (thisByte bitAnd:1) bitShift:7.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5496
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5497
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5498
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5499
     100000 asLargeInteger div2
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5500
     1000000000000000000000000000 div2
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5501
     10000000000000000000000000000000000000000000 div2
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5502
    "
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5503
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5504
    "Modified: 5.11.1996 / 16:12:56 / cg"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5505
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5506
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5507
mul2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5508
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5509
       destructively multiply the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5510
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5511
    |nBytes "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5512
     b      "{ Class: SmallInteger }"
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5513
     t prevBit|
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5514
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5515
    nBytes := digitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5516
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5517
    b := digitByteArray at:nBytes.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5518
    (b bitAnd:16r80) ~~ 0 ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5519
	"/ need another byte
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5520
	nBytes := nBytes + 1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5521
	t := ByteArray uninitializedNew:nBytes.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5522
	t replaceFrom:1 to:nBytes-1 with:digitByteArray startingAt:1.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5523
	t at:nBytes put:0.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5524
	digitByteArray := t.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5525
    ].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5526
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5527
%{
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5528
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5529
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5530
    if (__isByteArray(__digits)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5531
	int __nBytes = __intVal(nBytes);
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5532
	unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5533
	unsigned INT __carry = 0, __newCarry;
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5534
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5535
#if defined(__LSBFIRST__)
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5536
# if (__POINTER_SIZE__ == 8)
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5537
	if (sizeof(unsigned INT) == 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5538
	    while (__nBytes >= 8) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5539
		unsigned INT __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5540
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5541
		__this = ((unsigned INT *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5542
		__newCarry = (__this >> 63) /* & 1 */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5543
		((unsigned INT *)__bp)[0] = (__this << 1) | __carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5544
		__carry = __newCarry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5545
		__bp += 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5546
		__nBytes -= 8;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5547
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5548
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5549
# endif
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5550
	if (sizeof(unsigned int) == 4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5551
	    while (__nBytes >= 4) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5552
		unsigned int __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5553
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5554
		__this = ((unsigned int *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5555
		__newCarry = (__this >> 31) /* & 1 */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5556
		((unsigned int *)__bp)[0] = (__this << 1) | __carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5557
		__carry = __newCarry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5558
		__bp += 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5559
		__nBytes -= 4;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5560
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5561
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5562
	if (__nBytes >= 2) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5563
	    unsigned short __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5564
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5565
	    __this = ((unsigned short *)__bp)[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5566
	    __newCarry = (__this >> 15) /* & 1 */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5567
	    ((unsigned short *)__bp)[0] = (__this << 1) | __carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5568
	    __carry = __newCarry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5569
	    __bp += 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5570
	    __nBytes -= 2;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5571
	}
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5572
#endif /* LSBFIRST */
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5573
	while (__nBytes) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5574
	    unsigned char __this;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5575
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5576
	    __this = __bp[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5577
	    __newCarry = (__this >> 7) /* & 1 */;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5578
	    __bp[0] = (__this << 1) | __carry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5579
	    __carry = __newCarry;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5580
	    __bp++;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5581
	    __nBytes--;
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5582
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5583
	RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5584
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5585
%}.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5586
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5587
    prevBit := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5588
    1 to:digitByteArray size do:[:idx |
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5589
	|thisByte|
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5590
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5591
	thisByte := digitByteArray at:idx.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5592
	digitByteArray at:idx put:(((thisByte bitShift:1) bitAnd:16rFF) bitOr:prevBit).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5593
	prevBit := (thisByte bitShift:-7) bitAnd:1.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5594
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5595
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5596
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5597
     100000 asLargeInteger mul2
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5598
     16r7FFFFFFFFFFF copy mul2 hexPrintString
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5599
     16rFFFFFFFFFFFF copy mul2 hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5600
     16r7FFFFFFFFFFFFF copy mul2 hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5601
     16rFFFFFFFFFFFFFF copy mul2 hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5602
     10000000000000000000000000000 mul2
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5603
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5604
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5605
    "Modified: 5.11.1996 / 16:37:32 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5606
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5607
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5608
mul256
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5609
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5610
       destructively multiply the receiver by 256."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5611
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5612
    |newDigits newSize|
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5613
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5614
    newSize := digitByteArray size + 1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5615
    newDigits := ByteArray uninitializedNew:newSize.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5616
    newDigits replaceBytesFrom:2 to:newSize with:digitByteArray startingAt:1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5617
    newDigits at:1 put:0.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5618
    digitByteArray := newDigits
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5619
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5620
    "Modified: / 20.5.1999 / 09:16:42 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5621
!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5622
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5623
numberOfDigits:nDigits
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5624
    "allocate space for nDigits bytes of magnitude"
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19655
diff changeset
  5625
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5626
    digitByteArray := ByteArray new:nDigits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5627
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5628
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5629
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5630
numberOfDigits:nDigits sign:newSign
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5631
    "allocate space for nDigits bytes of magnitude"
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5632
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5633
    digitByteArray := ByteArray new:nDigits.
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5634
    sign := newSign.
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5635
!
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5636
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5637
setDigits:digits
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5638
    "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
  5639
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5640
    digitByteArray := digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5641
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5642
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5643
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5644
setDigits:digits sign:newSign
19650
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5645
    "set the digits from the lsb-ordered digit-bytes"
84b875892f4a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19606
diff changeset
  5646
18381
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5647
    digitByteArray := digits.
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5648
    sign := newSign.
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5649
!
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5650
7614c149c77e class: LargeInteger
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5651
setSign:aNumber
19260
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5652
    "destructively change the sign of the receiver.
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5653
     Return the compressed integer (smallinteger if possible)"
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5654
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5655
    sign := aNumber.
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5656
%{
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5657
    if (aNumber == __MKSMALLINT(-1)) {
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5658
	if (__byteArraySize(__INST(digitByteArray)) == sizeof(INT)) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5659
	    if ( ((INT *)(__byteArrayVal(__INST(digitByteArray))))[0] == -_MIN_INT) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5660
		RETURN(__MKSMALLINT(_MIN_INT));
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5661
	    }
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5662
	}
19260
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5663
    }
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5664
%}.
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5665
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5666
    "
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5667
     (LargeInteger digitBytes:#[0 0 0 64]) setSign:-1
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5668
    "
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5669
Claus Gittinger <cg@exept.de>
parents: 19256
diff changeset
  5670
    "Modified (comment): / 26-02-2016 / 22:40:27 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5671
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5672
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5673
!LargeInteger methodsFor:'queries'!
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5674
22726
5e76d6588adc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22380
diff changeset
  5675
isZero
5e76d6588adc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22380
diff changeset
  5676
    "the integer zero is always represented as a SmallInteger"
5e76d6588adc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22380
diff changeset
  5677
    
5e76d6588adc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22380
diff changeset
  5678
    ^ false
5e76d6588adc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22380
diff changeset
  5679
!
5e76d6588adc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22380
diff changeset
  5680
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5681
nextPowerOf2
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5682
    "return the power of 2 at or above the receiver.
19059
687547192a05 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19052
diff changeset
  5683
     Notice, that for a powerOf2, the receiver is returned.
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5684
     Also notice, that (because it is used for padding),
19059
687547192a05 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19052
diff changeset
  5685
     0 is returned for zero."
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5686
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5687
    |newBytes nBytes hi|
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5688
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5689
    "/ assume I am normalized
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5690
    nBytes := digitByteArray size.
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5691
    hi := digitByteArray at:nBytes.
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5692
    self assert:(hi ~~ 0).
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5693
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5694
    newBytes := ByteArray new:(nBytes) withAll:16rFF.
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5695
    (hi isPowerOf:2) ifTrue:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5696
	newBytes at:nBytes put:((hi bitShift:1)- 1).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5697
    ] ifFalse:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5698
	newBytes at:nBytes put:(hi nextPowerOf2 - 1).
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5699
    ].
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5700
    ^ (LargeInteger digitBytes:newBytes) + 1
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5701
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5702
    "
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5703
     100 factorial nextPowerOf2  isPowerOf:2
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5704
     1000 factorial nextPowerOf2  isPowerOf:2
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5705
     Time millisecondsToRun:[
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5706
	 |v|
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5707
	 v := 1000 factorial.
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5708
	 1000 timesRepeat:[
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5709
	    v nextPowerOf2
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5710
	 ]
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5711
     ]
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5712
    "
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5713
! !
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5714
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5715
!LargeInteger methodsFor:'testing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5716
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5717
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5718
    "return true if the receiver is even"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5719
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5720
%{  /* NOCONTEXT */
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5721
#ifdef __SCHTEAM__
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5722
    return context._RETURN( ((STLargeInteger)self).isEven() ? STObject.True : STObject.False);
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5723
#else
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5724
    OBJ digits = __INST(digitByteArray);
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5725
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5726
    if (__isByteArray(digits)){
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5727
	if (__byteArraySize(digits) > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5728
	    unsigned char b = __ByteArrayInstPtr(digits)->ba_element[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5729
	    RETURN( (b & 1) ? false : true );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5730
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5731
    }
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5732
#endif
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5733
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5734
    ^ (digitByteArray at:1) even
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5735
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5736
    "
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5737
     16r100000000000000000001 even
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5738
     16r100000000000000000001 odd
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5739
     16r100000000000000000000 even
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5740
     16r100000000000000000000 odd
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5741
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5742
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5743
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5744
negative
18855
85ed6541937d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18848
diff changeset
  5745
    "return true, if the receiver is less than zero"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5746
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5747
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  5748
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5749
    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
  5750
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5751
%}.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5752
    ^ (sign < 0)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5753
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5754
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5755
odd
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5756
    "return true if the receiver is odd"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5757
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5758
%{  /* NOCONTEXT */
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5759
#ifdef __SCHTEAM__
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5760
    return context._RETURN( ((STLargeInteger)self).isEven() ? STObject.False : STObject.True);
19102
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5761
#else
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5762
    OBJ digits = __INST(digitByteArray);
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5763
3ba85ef22c95 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19059
diff changeset
  5764
    if (__isByteArray(digits)){
19262
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5765
	if (__byteArraySize(digits) > 0) {
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5766
	    unsigned char b = __ByteArrayInstPtr(digits)->ba_element[0];
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5767
	    RETURN( (b & 1) ? true : false );
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5768
	}
cf39fe4ec276 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19260
diff changeset
  5769
    }
18903
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5770
#endif
5fc592d100b5 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18900
diff changeset
  5771
%}.
1983
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  5772
    ^ (digitByteArray at:1) odd
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  5773
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  5774
    "Modified: 18.11.1996 / 22:19:19 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5775
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5776
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5777
positive
18855
85ed6541937d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18848
diff changeset
  5778
    "return true, if the receiver is greater or equal to zero (not negative)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5779
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5780
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  5781
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5782
    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
  5783
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5784
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5785
    ^ (sign >= 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5786
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5787
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5788
sign
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7446
diff changeset
  5789
    "return the sign of the receiver (-1, 0 or 1)"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5790
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5791
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  5792
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5793
    return context._RETURN( STInteger._new( ((STLargeInteger)self).largeValue.signum() ));
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5794
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5795
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5796
    ^ sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5797
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5798
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5799
strictlyPositive
18855
85ed6541937d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18848
diff changeset
  5800
    "return true, if the receiver is greater than zero"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5801
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5802
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18235
diff changeset
  5803
#ifdef __SCHTEAM__
18235
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5804
    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
  5805
#endif
9f0914e019a8 experimental java support
Claus Gittinger <cg@exept.de>
parents: 17648
diff changeset
  5806
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5807
    ^ (sign > 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5808
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5809
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  5810
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5811
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5812
version
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
  5813
    ^ '$Header$'
12121
38c8767f98f2 changed: #bitAnd:
Claus Gittinger <cg@exept.de>
parents: 11959
diff changeset
  5814
!
38c8767f98f2 changed: #bitAnd:
Claus Gittinger <cg@exept.de>
parents: 11959
diff changeset
  5815
38c8767f98f2 changed: #bitAnd:
Claus Gittinger <cg@exept.de>
parents: 11959
diff changeset
  5816
version_CVS
18621
78b4a4b916a5 schteam change
Claus Gittinger <cg@exept.de>
parents: 18381
diff changeset
  5817
    ^ '$Header$'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5818
! !
19902
841154ab88d4 #REFACTORING by mawalch
mawalch
parents: 19900
diff changeset
  5819