Float.st
changeset 17653 ae0a317ee190
parent 17583 b85b038c4ea4
child 17657 424006f2570b
--- a/Float.st	Wed Mar 25 16:41:30 2015 +0100
+++ b/Float.st	Wed Mar 25 16:41:40 2015 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1988 by Claus Gittinger
 	      All Rights Reserved
@@ -396,6 +394,10 @@
     "
 !
 
+fromNumber:aNumber
+    ^aNumber asFloat
+!
+
 fromVAXFloatBytes:b1 b2:b2 b3:b3 b4:b4
     "creates a double, given the four vax float bytes to an ieee double.
      For NaNs and Infinity, nil is returned.
@@ -620,6 +622,26 @@
     ^ 2.7182818284590452353602874713526625
 !
 
+fmax
+    "The largest value allowed by the characterized
+    floating point object representation.  The answer
+    should be equal to
+
+    (1 - (self radix raisedTo: self precision negated))
+            * (self radix raisedTo: self emax + 1)
+
+    Note the ANSI spec says
+
+    (1 - (self radix raisedTo: self precision negated))
+            * (self radix raisedTo: self emax)
+
+    but this is not correct."
+
+    ^(self fromNumber: 1) -
+            ((self fromNumber: self radix) timesTwoPower: self precision negated - 1) * self radix
+            * ((self fromNumber: self radix) timesTwoPower: self emax - 1)
+!
+
 ln2
     "/ dont expect this many valid digits on all machines;
     "/ The actual precision is very CPU specific.
@@ -703,7 +725,6 @@
     "
 ! !
 
-
 !Float class methodsFor:'queries'!
 
 exponentCharacter
@@ -764,7 +785,6 @@
     ^ 2 "must be careful here, whenever ST/X is used on VAX or a 370"
 ! !
 
-
 !Float methodsFor:'arithmetic'!
 
 * aNumber
@@ -2175,7 +2195,6 @@
     "
 ! !
 
-
 !Float methodsFor:'testing'!
 
 isFinite
@@ -3089,11 +3108,11 @@
 !Float class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.210 2015-03-04 19:01:43 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.211 2015-03-25 15:41:40 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.210 2015-03-04 19:01:43 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.211 2015-03-25 15:41:40 cg Exp $'
 ! !