[squeak-dev] The Trunk: Kernel-nice.256.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] The Trunk: Kernel-nice.256.mcz

commits-2
Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.256.mcz

==================== Summary ====================

Name: Kernel-nice.256
Author: nice
Time: 4 October 2009, 9:50:10 am
UUID: a9171183-4c69-4fea-9279-058519685204
Ancestors: Kernel-nice.255

Fix for http://bugs.squeak.org/view.php?id=6781
self should: [0.0 raisedTo: -1.0] raise: ZeroDivide.

I used the license clean fix from Pharo here and also introduce license clean #raisedToInteger: #/ #reciprocal #one by GabrielOmarCotelli

This code is MIT as Gabriel signed the pharo agreement.

=============== Diff against Kernel-nice.255 ===============

Item was changed:
+ ----- Method: Fraction>>reciprocal (in category 'private') -----
- ----- Method: Fraction>>reciprocal (in category 'arithmetic') -----
  reciprocal
+
+ numerator abs = 1 ifTrue: [^denominator * numerator].
+ ^self class numerator: denominator denominator: numerator!
- "Refer to the comment in Number|reciprocal."
- #Numeric.
- "Changed 200/01/19 For ANSI <number> support."
- numerator = 0 ifTrue: [^ (ZeroDivide dividend: self) signal"<- Chg"].
- numerator = 1 ifTrue: [^ denominator].
- numerator = -1 ifTrue: [^ denominator negated].
- ^ Fraction numerator: denominator denominator: numerator!

Item was added:
+ ----- Method: Number class>>one (in category 'constants') -----
+ one
+
+ ^1!

Item was changed:
  ----- Method: Number>>reciprocal (in category 'arithmetic') -----
  reciprocal
+ "Returns the reciprocal of self.
+ In case self is 0 the / signals ZeroDivide"
+
+ ^1 / self!
- "Answer 1 divided by the receiver. Create an error notification if the
- receiver is 0."
- #Numeric.
- "Changed 200/01/19 For ANSI <number> support."
- self = 0 ifTrue: [^ (ZeroDivide dividend: self) signal"<- Chg"].
- ^ 1 / self!

Item was changed:
  ----- Method: Float class>>one (in category 'constants') -----
  one
+
+ ^1.0!
- #Numeric.
- "add 200/01/19 For <number> protocol support."
- ^ 1.0!

Item was changed:
  ----- Method: Float>>reciprocal (in category 'arithmetic') -----
  reciprocal
+
+ "Returns the reciprocal.
+ If self is 0.0 the / signals a ZeroDivide"
+
+ ^1.0 / self!
- #Numeric.
- "Changed 200/01/19 For ANSI <number> support."
- self = 0 ifTrue: ["<- Chg"
- ^ (ZeroDivide dividend: self) signal"<- Chg"].
- "<- Chg"
- ^ 1.0 / self!

Item was changed:
  ----- Method: Float>>/ (in category 'arithmetic') -----
  / aNumber
  "Primitive. Answer the result of dividing receiver by aNumber.
  Fail if the argument is not a Float. Essential. See Object documentation
  whatIsAPrimitive."
 
  <primitive: 50>
+ aNumber = 0.0 ifTrue: [ ZeroDivide signalWithDividend: self].
+ ^aNumber adaptToFloat: self andSend: #/!
- aNumber isZero ifTrue: [^(ZeroDivide dividend: self) signal].
- ^ aNumber adaptToFloat: self andSend: #/!

Item was changed:
  ----- Method: Number>>raisedToInteger: (in category 'mathematical functions') -----
+ raisedToInteger: anInteger
+
+ "The 0 raisedToInteger: 0 is an special case. In some contexts must be 1 and in others must
+ be handled as an indeterminate form.
+ I take the first context because that's the way that was previously handled.
+ Maybe further discussion is required on this topic."
+
+ |bitProbe result|
+
+ anInteger negative ifTrue: [^(self raisedToInteger: anInteger negated) reciprocal].
+ bitProbe := 1 bitShift: anInteger highBit - 1.
+   result := self class one.
+   [
+ (anInteger bitAnd: bitProbe) = 0 ifFalse: [result := result * self].
+        bitProbe := bitProbe bitShift: -1.
+ bitProbe > 0 ]
+ whileTrue: [result := result * result].
+
+ ^result!
- raisedToInteger: operand
- "Answer the receiver raised to the power operand, an Integer."
- | count result |
- #Numeric.
- "Changed 200/01/19 For ANSI <number> support."
- operand isInteger ifFalse: [^ ArithmeticError signal: 'parameter is not an Integer'"<- Chg"].
- operand = 0 ifTrue: [^ self class one].
- operand = 1 ifTrue: [^ self].
- operand < 0 ifTrue: [^ (self raisedToInteger: operand negated) reciprocal].
- count := 1.
- [(count := count + count) < operand] whileTrue.
- result := self class one.
- [count > 0]
- whileTrue:
- [result := result * result.
- (operand bitAnd: count)
- = 0 ifFalse: [result := result * self].
- count := count bitShift: -1].
- ^ result!

Item was changed:
  ----- Method: SmallInteger>>/ (in category 'arithmetic') -----
  / aNumber
  "Primitive. This primitive (for /) divides the receiver by the argument
  and returns the result if the division is exact. Fail if the result is not a
  whole integer. Fail if the argument is 0 or is not a SmallInteger. Optional.
  No Lookup. See Object documentation whatIsAPrimitive."
 
  <primitive: 10>
  aNumber isZero ifTrue: [^(ZeroDivide dividend: self) signal].
+ ^(aNumber isMemberOf: SmallInteger)
+ ifTrue: [(Fraction numerator: self denominator: aNumber) reduced]
+ ifFalse: [super / aNumber]!
- (aNumber isMemberOf: SmallInteger)
- ifTrue: [^(Fraction numerator: self denominator: aNumber) reduced]
- ifFalse: [^super / aNumber]!

Item was changed:
  ----- Method: Number>>integerPart (in category 'truncation and round off') -----
  integerPart
+ "Added for ANSI compatibility"
+ ^self truncated!
- "Answer the integer part of the receiver."
- #Numeric.
- "2000/03/04  Harmon R. Added ANSI <number> protocol"
- ^ self truncated!

Item was changed:
  ----- Method: Number>>fractionPart (in category 'truncation and round off') -----
  fractionPart
+
+ "Added for ANSI compatibility"
+
+ ^self - self integerPart!
- "Answer the fractional part of the receiver."
- #Numeric.
- "2000/03/04  Harmon R. Added ANSI <number> protocol"
- ^ self - self truncated!

Item was changed:
  ----- Method: Number>>raisedTo: (in category 'mathematical functions') -----
  raisedTo: aNumber
  "Answer the receiver raised to aNumber."
 
  aNumber isInteger ifTrue:
  ["Do the special case of integer power"
  ^ self raisedToInteger: aNumber].
  self < 0 ifTrue:
  [ self error: self printString, ' raised to a non-integer power' ].
+ 0 = aNumber ifTrue: [^ self class one]. "Special case of exponent=0"
+ 1 = aNumber ifTrue: [^ self]. "Special case of exponent=1"
+ 0 = self ifTrue: [ "Special case of self = 0"
+ aNumber < 0
+ ifTrue: [^ (ZeroDivide dividend: self) signal]
+ ifFalse: [^ self]].
- aNumber = 0 ifTrue: [^ 1]. "Special case of exponent=0"
- (self = 0) | (aNumber = 1) ifTrue:
- [^ self]. "Special case of exponent=1"
  ^ (aNumber * self ln) exp "Otherwise use logarithms"!

Item was removed:
- ----- Method: Float>>raisedTo: (in category 'mathematical functions') -----
- raisedTo: aNumber
- "Answer the receiver raised to aNumber."
-
- aNumber isInteger ifTrue:
- ["Do the special case of integer power"
- ^ self raisedToInteger: aNumber].
- self < 0.0 ifTrue:
- [ ArithmeticError signal: ' raised to a non-integer power' ].
- 0.0 = aNumber ifTrue: [^ 1.0]. "special case for exponent = 0.0"
- (self= 0.0) | (aNumber = 1.0) ifTrue: [^ self]. "special case for self = 1.0"
- ^ (self ln * aNumber asFloat) exp "otherwise use logarithms"
- !

Item was removed:
- ----- Method: Integer class>>one (in category 'constants') -----
- one
- #Numeric.
- "add 200/01/19 For <number> protocol support."
- ^ 1!

Item was removed:
- ----- Method: Fraction class>>one (in category 'constants') -----
- one
- #Numeric.
- "add 200/01/19 For <number> protocol support."
- ^ self numerator: 1 denominator: 1!