7436
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2003 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
18831
|
12 |
"{ Package: 'stx:libbasic' }"
|
7436
|
13 |
|
18831
|
14 |
"{ NameSpace: Smalltalk }"
|
7436
|
15 |
|
|
16 |
Number subclass:#MetaNumber
|
|
17 |
instanceVariableNames:''
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Magnitude-Numbers'
|
|
21 |
!
|
|
22 |
|
|
23 |
!MetaNumber class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2003 by eXept Software AG
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
Common behavior for metaNumbers (INF, NaN).
|
|
42 |
|
|
43 |
[author:]
|
|
44 |
Claus Gittinger
|
|
45 |
|
|
46 |
[see also:]
|
|
47 |
Number Infinity NotANumber
|
|
48 |
Float ShortFloat Fraction FixedPoint Integer Complex
|
|
49 |
FloatArray DoubleArray
|
|
50 |
"
|
|
51 |
! !
|
|
52 |
|
18916
|
53 |
!MetaNumber class methodsFor:'queries'!
|
|
54 |
|
|
55 |
isAbstract
|
|
56 |
^ self == MetaNumber
|
|
57 |
! !
|
|
58 |
|
7436
|
59 |
!MetaNumber methodsFor:'coercing & converting'!
|
|
60 |
|
|
61 |
asFloat
|
21893
|
62 |
"return a Float with same value as the receiver.
|
|
63 |
For anything but NaN, +Inf or -Inf, an error is raised here."
|
|
64 |
|
|
65 |
^ self asInstanceOf:Float fromSelector:#asFloat.
|
|
66 |
|
|
67 |
"Modified: / 21-06-2017 / 20:41:03 / cg"
|
7436
|
68 |
!
|
|
69 |
|
|
70 |
asFraction
|
|
71 |
^ self class
|
|
72 |
raise:#domainErrorSignal
|
|
73 |
receiver:self
|
|
74 |
selector:#asFraction
|
|
75 |
arguments:#()
|
|
76 |
errorString:'Cannot represent non-finite as fraction'.
|
|
77 |
!
|
|
78 |
|
21893
|
79 |
asInstanceOf:aFloatClass fromSelector:selector
|
|
80 |
"common code for asShortFloat, asFloat, ...
|
|
81 |
Return an instance of aFloatClass with same value as the receiver.
|
|
82 |
For anything but NaN, +Inf or -Inf, an error is raised here."
|
|
83 |
|
|
84 |
self isNaN ifTrue:[ ^ aFloatClass NaN ].
|
|
85 |
self isInfinite ifTrue:[
|
|
86 |
self negative ifTrue:[
|
|
87 |
^ aFloatClass negativeInfinity
|
|
88 |
].
|
|
89 |
^ aFloatClass infinity
|
|
90 |
].
|
|
91 |
|
|
92 |
^ self class
|
|
93 |
raise:#domainErrorSignal
|
|
94 |
receiver:self
|
|
95 |
selector:selector
|
|
96 |
arguments:#()
|
|
97 |
errorString:'Cannot represent non-finite as float'.
|
|
98 |
|
|
99 |
"Created: / 21-06-2017 / 20:40:35 / cg"
|
|
100 |
!
|
|
101 |
|
7436
|
102 |
asInteger
|
|
103 |
^ self class
|
|
104 |
raise:#domainErrorSignal
|
|
105 |
receiver:self
|
|
106 |
selector:#asInteger
|
|
107 |
arguments:#()
|
|
108 |
errorString:'Cannot represent non-finite as integer'.
|
|
109 |
!
|
|
110 |
|
|
111 |
asLargeFloat
|
|
112 |
^ self class
|
|
113 |
raise:#domainErrorSignal
|
|
114 |
receiver:self
|
|
115 |
selector:#asLargeFloat
|
|
116 |
arguments:#()
|
|
117 |
errorString:'Cannot represent non-finite as float'.
|
|
118 |
!
|
|
119 |
|
|
120 |
asLongFloat
|
21893
|
121 |
"return a LongFloat with same value as the receiver.
|
|
122 |
For anything but NaN, +Inf or -Inf, an error is raised here."
|
|
123 |
|
|
124 |
^ self asInstanceOf:LongFloat fromSelector:#asLongFloat.
|
|
125 |
|
|
126 |
"Modified: / 21-06-2017 / 20:41:26 / cg"
|
|
127 |
!
|
|
128 |
|
|
129 |
asQDouble
|
|
130 |
"return a QDouble with same value as the receiver.
|
|
131 |
For anything but NaN, +Inf or -Inf, an error is raised here."
|
|
132 |
|
|
133 |
^ self asInstanceOf:QDouble fromSelector:#asQDouble
|
|
134 |
|
|
135 |
"
|
|
136 |
Infinity NaN asFloat
|
|
137 |
Infinity NaN asQDouble
|
|
138 |
|
|
139 |
Infinity positive asFloat
|
|
140 |
Infinity positive asQDouble
|
|
141 |
|
|
142 |
Infinity negative asFloat
|
|
143 |
Infinity negative asQDouble
|
|
144 |
"
|
|
145 |
|
|
146 |
"Created: / 21-06-2017 / 20:42:09 / cg"
|
7436
|
147 |
!
|
|
148 |
|
|
149 |
asShortFloat
|
21893
|
150 |
"return a Float with same value as the receiver.
|
|
151 |
For anything but NaN, +Inf or -Inf, an error is raised here."
|
|
152 |
|
|
153 |
^ self asInstanceOf:ShortFloat fromSelector:#asShortFloat.
|
|
154 |
|
|
155 |
"Modified: / 21-06-2017 / 20:41:41 / cg"
|
7436
|
156 |
!
|
|
157 |
|
|
158 |
coerce:aNumber
|
18831
|
159 |
"convert the argument aNumber into an instance of the receiver's class and return it."
|
|
160 |
|
7436
|
161 |
^ aNumber asMetaNumber
|
|
162 |
!
|
|
163 |
|
|
164 |
generality
|
|
165 |
"NaN, INF etc. are more general than scalars, but not more general than
|
|
166 |
vectors (e.g. Points)"
|
|
167 |
|
|
168 |
^ 105
|
|
169 |
! !
|
|
170 |
|
|
171 |
!MetaNumber class methodsFor:'documentation'!
|
|
172 |
|
|
173 |
version
|
18831
|
174 |
^ '$Header$'
|
7436
|
175 |
! !
|
18831
|
176 |
|