#BUGFIX by cg
class: LargeFloat
NaN and Inf fixes
comment/format in: #negative
changed:
#asFloat
#asTrueFraction
#positive
"
COPYRIGHT (c) 2003 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
"{ Package: 'stx:libbasic' }"
"{ NameSpace: Smalltalk }"
Number subclass:#MetaNumber
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Magnitude-Numbers'
!
!MetaNumber class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 2003 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
!
documentation
"
Common behavior for metaNumbers (INF, NaN).
[author:]
Claus Gittinger
[see also:]
Number Infinity NotANumber
Float ShortFloat Fraction FixedPoint Integer Complex
FloatArray DoubleArray
"
! !
!MetaNumber class methodsFor:'queries'!
isAbstract
^ self == MetaNumber
! !
!MetaNumber methodsFor:'coercing & converting'!
asFloat
"return a Float with same value as the receiver.
For anything but NaN, +Inf or -Inf, an error is raised here."
^ self asInstanceOf:Float fromSelector:#asFloat.
"Modified: / 21-06-2017 / 20:41:03 / cg"
!
asFraction
^ self class
raise:#domainErrorSignal
receiver:self
selector:#asFraction
arguments:#()
errorString:'Cannot represent non-finite as fraction'.
!
asInstanceOf:aFloatClass fromSelector:selector
"common code for asShortFloat, asFloat, ...
Return an instance of aFloatClass with same value as the receiver.
For anything but NaN, +Inf or -Inf, an error is raised here."
self isNaN ifTrue:[ ^ aFloatClass NaN ].
self isInfinite ifTrue:[
self negative ifTrue:[
^ aFloatClass negativeInfinity
].
^ aFloatClass infinity
].
^ self class
raise:#domainErrorSignal
receiver:self
selector:selector
arguments:#()
errorString:'Cannot represent non-finite as float'.
"Created: / 21-06-2017 / 20:40:35 / cg"
!
asInteger
^ self class
raise:#domainErrorSignal
receiver:self
selector:#asInteger
arguments:#()
errorString:'Cannot represent non-finite as integer'.
!
asLargeFloat
^ self class
raise:#domainErrorSignal
receiver:self
selector:#asLargeFloat
arguments:#()
errorString:'Cannot represent non-finite as float'.
!
asLongFloat
"return a LongFloat with same value as the receiver.
For anything but NaN, +Inf or -Inf, an error is raised here."
^ self asInstanceOf:LongFloat fromSelector:#asLongFloat.
"Modified: / 21-06-2017 / 20:41:26 / cg"
!
asQDouble
"return a QDouble with same value as the receiver.
For anything but NaN, +Inf or -Inf, an error is raised here."
^ self asInstanceOf:QDouble fromSelector:#asQDouble
"
Infinity NaN asFloat
Infinity NaN asQDouble
Infinity positive asFloat
Infinity positive asQDouble
Infinity negative asFloat
Infinity negative asQDouble
"
"Created: / 21-06-2017 / 20:42:09 / cg"
!
asShortFloat
"return a Float with same value as the receiver.
For anything but NaN, +Inf or -Inf, an error is raised here."
^ self asInstanceOf:ShortFloat fromSelector:#asShortFloat.
"Modified: / 21-06-2017 / 20:41:41 / cg"
!
coerce:aNumber
"convert the argument aNumber into an instance of the receiver's class and return it."
^ aNumber asMetaNumber
!
generality
"NaN, INF etc. are more general than scalars, but not more general than
vectors (e.g. Points)"
^ 105
! !
!MetaNumber class methodsFor:'documentation'!
version
^ '$Header$'
! !