The Trunk: KernelTests-nice.268.mcz

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

The Trunk: KernelTests-nice.268.mcz

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

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

Name: KernelTests-nice.268
Author: nice
Time: 3 May 2014, 10:37:15.215 pm
UUID: e0058bc7-5cbc-43da-a0d6-34b19b06a6d5
Ancestors: KernelTests-eem.267

Now that there is a direct access to Float negativeInfinity, use it.

=============== Diff against KernelTests-eem.267 ===============

Item was changed:
  ----- Method: FloatTest>>testCharacterization (in category 'characterization') -----
  testCharacterization
 
  "Test the largest finite representable floating point value"
  self assert: Float fmax successor = Float infinity.
  self assert: Float infinity predecessor = Float fmax.
+ self assert: Float fmax negated predecessor = Float negativeInfinity.
+ self assert: Float negativeInfinity successor = Float fmax negated.
- self assert: Float fmax negated predecessor = Float infinity negated.
- self assert: Float infinity negated successor = Float fmax negated.
 
  "Test the smallest positive representable floating point value"
  self assert: Float fmin predecessor = 0.0.
  self assert: 0.0 successor = Float fmin.
  self assert: Float fmin negated successor = 0.0.
  self assert: 0.0 predecessor = Float fmin negated.
 
  "Test the relative precision"
  self assert: Float one + Float epsilon > Float one.
  self assert: Float one + Float epsilon = Float one successor.
  self assert: Float one + (Float epsilon / Float radix) = Float one.
 
  "Test maximum and minimum exponent"
  self assert: Float fmax exponent = Float emax.
  self assert: Float fminNormalized exponent = Float emin.
  Float denormalized ifTrue: [
  self assert: Float fminDenormalized exponent = (Float emin + 1 - Float precision)].
 
  "Alternative tests for maximum and minimum"
  self assert: (Float radix - Float epsilon) * (Float radix raisedTo: Float emax) = Float fmax.
  self assert: Float epsilon * (Float radix raisedTo: Float emin) = Float fmin.
 
  "Test sucessors and predecessors"
  self assert: Float one predecessor successor = Float one.
  self assert: Float one successor predecessor = Float one.
  self assert: Float one negated predecessor successor = Float one negated.
  self assert: Float one negated successor predecessor = Float one negated.
  self assert: Float infinity successor = Float infinity.
+ self assert: Float negativeInfinity predecessor = Float negativeInfinity.
- self assert: Float infinity negated predecessor = Float infinity negated.
  self assert: Float fmin negated successor = 0.0.
  self assert: Float fmin negated successor sign = -1.
  self assert: Float nan predecessor isNaN.
  self assert: Float nan successor isNaN.
 
  "SPECIFIC FOR IEEE 754 double precision - 64 bits"
  self assert: Float fmax hex = '7FEFFFFFFFFFFFFF'.
  self assert: Float fminDenormalized hex = '0000000000000001'.
  self assert: Float fminNormalized hex = '0010000000000000'.
  self assert: 0.0 hex = '0000000000000000'.
  self assert: Float negativeZero hex = '8000000000000000'.
  self assert: Float one hex = '3FF0000000000000'.
  self assert: Float infinity hex = '7FF0000000000000'.
+ self assert: Float negativeInfinity hex = 'FFF0000000000000'.!
- self assert: Float infinity negated hex = 'FFF0000000000000'.!

Item was changed:
  ----- Method: FloatTest>>testComparison (in category 'testing compare') -----
  testComparison
 
  "test equality when Float conversion loose bits"
  | a b c |
  a := 16r1FFFFFFFFFFFFF1.
  b := 16r1FFFFFFFFFFFFF3.
  c := a asFloat.
  self assert: ((a = c) & (b = c)) ==> (a = b).
 
  "Test equality when Float conversion exact"
  self assert: 16r1FFFFFFFFFFFFF = 16r1FFFFFFFFFFFFF asFloat.
  self assert: 16r1FFFFFFFFFFFFF = 16r1FFFFFFFFFFFFF asFloat asInteger.
 
  "Test inequality when Float conversion loose bits"
  self assert: (((1 bitShift: 54)+1)/(1 bitShift: 54)) > 1.
  self assert: (((1 bitShift: 54)+1)/(1 bitShift: 54)) > 1.0.
 
  self assert: (((1 bitShift: 54)-1)/(1 bitShift: 54)) < 1.
  self assert: (((1 bitShift: 54)-1)/(1 bitShift: 54)) < 1.0.
 
  "Test exact vs inexact arithmetic"
  (1 to: 100) do: [:i |
  i isPowerOfTwo
  ifTrue: [self assert: (1/i) = (1/i) asFloat]
  ifFalse: [self deny: (1/i) = (1/i) asFloat]].
 
  "Test overflow (compare to infinity)"
  a := (11 raisedTo: 400) / 2.
  b := (13 raisedTo: 400) / 2.
  c := a asFloat.
  self assert: ((a = c) & (b = c)) ==> (a = b).
 
  "every integer is smaller than infinity"
  self assert: a < Float infinity.
+ self assert: a > Float negativeInfinity.
- self assert: a > Float infinity negated.
 
  "Test underflow"
  self deny: 1 / (11 raisedTo: 400) = 0.
  self deny: 1 / (11 raisedTo: 400) = 0.0.
 
  "Test hash code"
  self assert:
  ((Set new: 3) add: 3; add: 3.0; size) =
  ((Set new: 4) add: 3; add: 3.0; size).!

Item was changed:
  ----- Method: FloatTest>>testCopy (in category 'testing') -----
  testCopy
  "Elementary tests"
  self assert: 2.0 copy = 2.0.
  self assert: -0.5 copy = -0.5.
 
  "Are exceptional Floats preserved by the copy ?"
  self assert: Float nan copy isNaN.
  self assert: Float infinity copy = Float infinity.
+ self assert: Float negativeInfinity copy = Float negativeInfinity.
- self assert: Float infinity negated copy = Float infinity negated.
 
  "Is the sign of zero preserved by the copy ?"
  self assert: 0.0 copy hex = 0.0 hex.
  self assert: Float negativeZero copy hex = Float negativeZero hex.!

Item was changed:
  ----- Method: FloatTest>>testDegreeCosForExceptionalValues (in category 'tests - mathematical functions') -----
  testDegreeCosForExceptionalValues
  self assert: Float nan degreeCos isNaN.
  self assert: Float infinity degreeCos isNaN.
+ self assert: Float negativeInfinity degreeCos isNaN.!
- self assert: Float infinity negated degreeCos isNaN.!

Item was changed:
  ----- Method: FloatTest>>testDegreeSinForExceptionalValues (in category 'tests - mathematical functions') -----
  testDegreeSinForExceptionalValues
  self assert: Float nan degreeSin isNaN.
  self assert: Float infinity degreeSin isNaN.
+ self assert: Float negativeInfinity degreeSin isNaN.!
- self assert: Float infinity negated degreeSin isNaN.!

Item was changed:
  ----- Method: FloatTest>>testInfinity3 (in category 'IEEE 754') -----
  testInfinity3
+ self assert: (Float negativeInfinity asIEEE32BitWord printPaddedWith: $0 to: 32 base: 2) =
- self assert: (Float infinity negated asIEEE32BitWord printPaddedWith: $0 to: 32 base: 2) =
  '11111111100000000000000000000000'.
  self assert: (Float fromIEEE32Bit:
  (Integer readFrom: '11111111100000000000000000000000' readStream base: 2))
+ = Float negativeInfinity!
- = Float infinity negated!

Item was changed:
  ----- Method: FloatTest>>testInfinityCloseTo (in category 'infinity behavior') -----
  testInfinityCloseTo
  "This is a test for bug http://bugs.squeak.org/view.php?id=6729:"
 
    "FloatTest new testInfinityCloseTo"
 
+ self deny: (Float infinity closeTo: Float negativeInfinity).
+ self deny: (Float negativeInfinity closeTo: Float infinity).!
- self deny: (Float infinity closeTo: Float infinity negated).
- self deny: (Float infinity negated closeTo: Float infinity).!

Item was changed:
  ----- Method: FloatTest>>testSign (in category 'testing') -----
  testSign
 
  "Set up"
  | negatives negz positives strictNegatives strictPositives zero |
  strictPositives := {2. 2.5. Float infinity}.
+ strictNegatives := {-3. -3.25. Float negativeInfinity}.
- strictNegatives := {-3. -3.25. Float infinity negated}.
  zero := 0.0.
  negz := Float negativeZero.
  positives := strictPositives copyWith: zero.
  negatives := strictNegatives copyWith: negz.
 
  "The sign of non zeros"
  strictPositives do: [:aPositive | self assert: aPositive sign = 1].
  strictNegatives do: [:aNegative | self assert: aNegative sign = -1].
 
  "The sign of zeros"
  self assert: zero sign = 0.
  self assert: negz sign = -1. "remark though that negz >= 0.0, and is thus considered positive... Weird"
 
  "Test the copy sign functions"
  positives do: [:aPositiveSign |
  positives do: [:aPositive |
  self assert: (aPositive sign: aPositiveSign) = aPositive].
  negatives do: [:aNegative |
  self assert: (aNegative sign: aPositiveSign) = aNegative negated].
  (zero sign: aPositiveSign) sign = 0.
  (negz sign: aPositiveSign) sign = 0].
 
  negatives do: [:aNegativeSign |
  positives do: [:aPositive |
  self assert: (aPositive sign: aNegativeSign) = aPositive negated].
  negatives do: [:aNegative |
  self assert: (aNegative sign: aNegativeSign) = aNegative].
  (zero sign: aNegativeSign) sign = -1.
  (negz sign: aNegativeSign) sign = -1].!

Item was changed:
  ----- Method: FloatTest>>testSignificandAndExponent (in category 'characterization') -----
  testSignificandAndExponent
  | denormals exceptionals normals |
 
  normals := {Float pi. Float pi * 100.0. Float pi/ -100.0. Float fmax. Float fminNormalized}.
  denormals := {0.0. Float negativeZero. Float fminNormalized predecessor. Float fmin negated}.
+ exceptionals := {Float nan. Float infinity. Float negativeInfinity.}.
- exceptionals := {Float nan. Float infinity. Float infinity negated.}.
 
  normals , denormals , exceptionals do: [:aFloat |
  "Any Float can be decomposed into its significand and exponent, and the significand holds the sign"
  aFloat isNaN
  ifTrue: [self assert: (aFloat significand timesTwoPower: aFloat exponent) isNaN]
  ifFalse: [self
  assert: (aFloat significand timesTwoPower: aFloat exponent)
  equals: aFloat]].
 
  normals , denormals do: [:aFloat |
  "The significand magnitude is in interval [1.0,2.0( "
  aFloat = 0.0
  ifTrue: [self assert: aFloat significand equals: 0]
  ifFalse: [self
  assert: aFloat significand abs >= 1.0;
  assert: aFloat significand abs < 2.0]]!

Item was changed:
  ----- Method: FloatTest>>testSignificandAsInteger (in category 'characterization') -----
  testSignificandAsInteger
  | mantissaBits denormalPowersOfTwo denormals exceptionals normalPowersOfTwo normals |
  "There are 52 bits used for representing the mantissa (plus an eventual leading 1, see below)"
  mantissaBits := Float precision - 1.
 
  normals := {Float pi. Float pi * 100.0. Float pi/ -100.0. Float fmax. Float fminNormalized}.
  denormals := {0.0. Float negativeZero. Float fminNormalized predecessor. Float fmin negated}.
+ exceptionals := {Float nan. Float infinity. Float negativeInfinity.}.
- exceptionals := {Float nan. Float infinity. Float infinity negated.}.
  normalPowersOfTwo := (-10 to: 10) collect: [:i | 1.0 timesTwoPower: i].
  denormalPowersOfTwo := (Float emin - mantissaBits to: Float emin - 1) collect: [:i | 1.0 timesTwoPower: i].
 
  normals do: [:aNormalFloat |
  "Assume the mantissa is written in least 52 bits of hex format, with an implied 1 on position 53"
  self
  assert: (((Integer readFrom: aNormalFloat hex base: 16) bitAnd: 1<<mantissaBits-1) bitOr: 1<<mantissaBits)
  equals: aNormalFloat significandAsInteger].
 
  denormals , exceptionals do: [:aDenormalOrExceptionalFloat |
  "For every other Float, zero, denormal or exceptional, no implied leading one"
  self
  assert: ((Integer readFrom: aDenormalOrExceptionalFloat hex base: 16) bitAnd: 1<<mantissaBits-1)
  equals: aDenormalOrExceptionalFloat significandAsInteger].
 
  normalPowersOfTwo do: [:aNormalPowerOfTwoFloat |
  "The significand of a power of two is a power of two, with high bit of expected precision"
  self assert: aNormalPowerOfTwoFloat significandAsInteger isPowerOfTwo.
  self assert: aNormalPowerOfTwoFloat significandAsInteger highBit equals: Float precision.
  self assert: aNormalPowerOfTwoFloat successor significandAsInteger equals: aNormalPowerOfTwoFloat significandAsInteger + 1.
  "The last one is not true for fminNormalized"
  aNormalPowerOfTwoFloat = Float fminNormalized or: [
  self assert: aNormalPowerOfTwoFloat predecessor significandAsInteger equals: aNormalPowerOfTwoFloat significandAsInteger * 2 - 1]].
 
  denormalPowersOfTwo do: [:aDenormalPowerOfTwoFloat |
  "The significand of a denormal power of two is a power of two, just with less bits"
  self assert: aDenormalPowerOfTwoFloat significandAsInteger isPowerOfTwo.
  self assert: aDenormalPowerOfTwoFloat significandAsInteger highBit equals: Float precision + aDenormalPowerOfTwoFloat exponent - Float emin.
  aDenormalPowerOfTwoFloat successor = Float fminNormalized or: [
  self assert: aDenormalPowerOfTwoFloat successor significandAsInteger equals: aDenormalPowerOfTwoFloat significandAsInteger + 1].
  self assert: aDenormalPowerOfTwoFloat predecessor significandAsInteger equals: aDenormalPowerOfTwoFloat significandAsInteger - 1.].
 
  "Well known value for a few extremal cases"
  self assert: Float fmax significandAsInteger equals: 1 << Float precision - 1.
  self assert: Float fmin significandAsInteger equals: 1.
  self assert: 0.0 significandAsInteger equals: 0.
  self assert: Float infinity significandAsInteger equals: 0.
  self assert: Float nan significandAsInteger > 0!

Item was changed:
  ----- Method: FloatTest>>testStoreOn (in category 'testing') -----
  testStoreOn
  "If storeOn: prints exactly and the parser avoid cumulating round off Errors,
  then Float should be read back exactly.
  Note: there is no guarantee to restore the bit pattern of NaN though"
 
  self assert: (Compiler evaluate: Float halfPi storeString) = Float halfPi.
  self assert: (Compiler evaluate: Float halfPi negated storeString) = Float halfPi negated.
  self assert: (Compiler evaluate: Float infinity storeString) = Float infinity.
+ self assert: (Compiler evaluate: Float negativeInfinity storeString) = Float negativeInfinity.
- self assert: (Compiler evaluate: Float infinity negated storeString) = Float infinity negated.
  self assert: (Compiler evaluate: Float nan storeString) isNaN.!

Item was changed:
  ----- Method: FloatTest>>testUlp (in category 'characterization') -----
  testUlp
 
  {Float pi predecessor. Float pi. Float pi successor} do:
  [:f |
  self assert: (f * 2) ulp = (f ulp * 2).
  self assert: (f / 2) ulp = (f ulp / 2).
  self deny: f + f ulp = f.
  self deny: f - f ulp = f.
  "Tests below are valid as long as default rounding mode (to nearest even) is used"
  self assert: f significandAsInteger odd ==> (f ulp / 2.0 + f = f successor).
  self assert: f significandAsInteger even ==> (f ulp / 2.0 + f = f)].
 
  self assert: 0.0 ulp = Float fmin.
  self assert: 1.0 ulp = Float epsilon.
  self assert: Float nan ulp isNaN.
  self assert: Float infinity ulp = Float infinity.
+ self assert: Float negativeInfinity ulp = Float infinity.
- self assert: Float infinity negated ulp = Float infinity.
 
  self assert: ((0 to: Float precision - 1) allSatisfy: [:each | (Float fmin timesTwoPower: each) ulp = Float fmin]). !

Item was changed:
  ----- Method: NumberTest>>testZeroDivideHandler (in category 'tests') -----
  testZeroDivideHandler
  "Test for user-defined ZeroDivide behavior"
 
  [
  self assert: 1 / 0 = Float infinity.
+ self assert: -1 / 0 = Float negativeInfinity.
- self assert: -1 / 0 = Float infinity negated.
  self assert: 1.0 / 0 = Float infinity.
+ self assert: -1.0 / 0 = Float negativeInfinity.
- self assert: -1.0 / 0 = Float infinity negated.
  self assert: 1 / 0.0 = Float infinity.
+ self assert: -1 / 0.0 = Float negativeInfinity.
- self assert: -1 / 0.0 = Float infinity negated.
  self assert: 1.0 / 0.0 = Float infinity.
+ self assert: -1.0 / 0.0 = Float negativeInfinity.
- self assert: -1.0 / 0.0 = Float infinity negated.
  ] on: ZeroDivide
  do: [:ex | ex resume: ex dividend sign * Float infinity ]
  !