The Trunk: Kernel-nice.1259.mcz

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

The Trunk: Kernel-nice.1259.mcz

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

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

Name: Kernel-nice.1259
Author: nice
Time: 20 August 2019, 10:58:50.044539 am
UUID: fcd050cd-0337-8f4c-a1c3-b04d0eef3b0a
Ancestors: Kernel-nice.1258

Accelerate mixed Integer/Fraction comparison.

Implementation note: we can assume that Fraction are properly reduced, failing to do so is programmer responsibility.

If someone cheat by using numerator:denominator: instead of / to avoid a costly gcd:, then someone will care to not get caught.

=============== Diff against Kernel-nice.1258 ===============

Item was changed:
  ----- Method: Fraction>>= (in category 'comparing') -----
  = aNumber
  aNumber isNumber ifFalse: [^ false].
+ aNumber isInteger ifTrue: ["If properly reduced, self cannot be an Integer" ^ false].
  aNumber isFraction
+ ifTrue: ["Assume that both Fraction are reduced"
+ ^ numerator = aNumber numerator and:
+ [denominator = aNumber denominator]].
- ifTrue: [numerator = 0 ifTrue: [^ aNumber numerator = 0].
- ^ (numerator * aNumber denominator) =
- (aNumber numerator * denominator)
- "Note: used to just compare num and denom,
- but this fails for improper fractions"].
  ^ aNumber adaptToFraction: self andCompare: #=!

Item was added:
+ ----- Method: Fraction>>adaptToInteger:andCompare: (in category 'converting') -----
+ adaptToInteger: rcvr andCompare: selector
+ "Assuming that self is properly reduced, it cannot be an Integer"
+ selector == #= ifTrue: [^false].
+ selector == #~= ifTrue: [^true].
+ "Inequality: avoid division with this transformation:
+ rcvr op: (num/den)
+ rcvr - (num/den) op: 0
+ rcvr*den op: num"
+ ^rcvr * denominator perform: selector with: numerator!