RegressionTests__FloatTest.st
changeset 1969 6a390fdc154c
parent 1915 af63d419f526
child 1970 4a060a60ea4e
equal deleted inserted replaced
1943:53713f32583c 1969:6a390fdc154c
    10 	poolDictionaries:''
    10 	poolDictionaries:''
    11 	category:'tests-Regression-Numbers'
    11 	category:'tests-Regression-Numbers'
    12 !
    12 !
    13 
    13 
    14 
    14 
    15 !FloatTest methodsFor:'helpers'!
    15 !FloatTest class methodsFor:'helpers'!
    16 
    16 
    17 actualPrecisionOf:aFloatClass
    17 actualPrecisionOf:aFloatClass
    18     "get the actual number of valid bits in the mantissa.
    18     "get the actual number of valid bits in the mantissa.
    19      This does a real test (i.e. does not believe the compiled-in ifdefs)"
    19      This does a real test (i.e. does not believe the compiled-in ifdefs)"
    20 
    20 
    21     |one x count two|
    21     |one x count|
       
    22 
       
    23 
       
    24 "/ For LongFloat the worng value 53 is returned!!
       
    25 "/ See: https://sourceforge.net/p/mingw-w64/bugs/678/
       
    26 "/ Fix it here with:
       
    27 "/%{
       
    28 "/    __asm__ ("fninit");
       
    29 "/%}.
    22 
    30 
    23     one := aFloatClass unity.  "/ 1.0 in this class
    31     one := aFloatClass unity.  "/ 1.0 in this class
    24     two := one coerce:2.0.
       
    25     x := one.
    32     x := one.
    26     count := 0.
    33     count := 0.
    27 
    34 
    28     [one + x > one] whileTrue:[
    35     [one + x > one] whileTrue:[
    29 	x := x / two.
    36         x := x / 2.
    30 	count := count + 1.
    37         count := count + 1.
    31     ].
    38     ].
    32     ^ count
    39     ^ count
    33 
    40 
    34     "
    41     "
    35      self basicNew actualPrecisionOf:ShortFloat
    42      self actualPrecisionOf:ShortFloat
    36      self basicNew actualPrecisionOf:Float
    43      self actualPrecisionOf:Float
    37      self basicNew actualPrecisionOf:LongFloat
    44      self actualPrecisionOf:LongFloat
    38     "
    45     "
    39 ! !
    46 ! !
    40 
    47 
    41 !FloatTest methodsFor:'tests'!
    48 !FloatTest methodsFor:'tests'!
    42 
    49 
    43 test00_Precision
    50 test00_Precision
    44     "computed precision vs. assumed precision."
    51     "computed precision vs. assumed precision."
    45 
    52 
    46     |a b|
    53     |a b|
    47 
    54 
    48     self assert:( (a := Float precision) = (b := self actualPrecisionOf:Float))
    55     self assert:( (a := Float precision) = (b := self class actualPrecisionOf:Float))
    49 		description:('Float precision: %1 ~~ actual: %2' bindWith:a with:b).
    56                 description:('Float precision: %1 ~~ actual: %2' bindWith:a with:b).
    50     self assert:( (a := ShortFloat precision) = (b := self actualPrecisionOf:ShortFloat))
    57     self assert:( (a := ShortFloat precision) = (b := self class actualPrecisionOf:ShortFloat))
    51 		description:('ShortFloat precision: %1 ~~ actual: %2' bindWith:a with:b).
    58                 description:('ShortFloat precision: %1 ~~ actual: %2' bindWith:a with:b).
    52     self assert:( (a := LongFloat precision) = (b := self actualPrecisionOf:LongFloat))
    59     self assert:( (a := LongFloat precision) = (b := self class actualPrecisionOf:LongFloat))
    53 		description:('LongFloat precision: %1 ~~ actual: %2' bindWith:a with:b).
    60                 description:('LongFloat precision: %1 ~~ actual: %2' bindWith:a with:b).
    54 
    61 
    55     "
    62     "
    56      self basicNew test00_Precision
    63      self basicNew test00_Precision
    57     "
    64     "
    58 
    65