author | Claus Gittinger <cg@exept.de> |
Wed, 14 Jan 2009 23:06:10 +0100 | |
changeset 11458 | d668f83e44d1 |
parent 11224 | a9a66cee404f |
child 11460 | 146fb82b5523 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
5322 | 3 |
All Rights Reserved |
1 | 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 |
" |
|
5360 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
1 | 14 |
ArithmeticValue subclass:#Number |
3900
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
15 |
instanceVariableNames:'' |
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
16 |
classVariableNames:'DecimalPointCharacter DecimalPointCharacterForPrinting |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
17 |
DecimalPointCharacters DecimalPointCharactersForReading' |
3900
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
18 |
poolDictionaries:'' |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
19 |
category:'Magnitude-Numbers' |
1 | 20 |
! |
21 |
||
1892 | 22 |
!Number class methodsFor:'documentation'! |
88 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
5322 | 27 |
All Rights Reserved |
1 | 28 |
|
88 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
1 | 37 |
|
88 | 38 |
documentation |
39 |
" |
|
40 |
abstract superclass for all kinds of numbers |
|
1295 | 41 |
|
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
42 |
[class variables:] |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
43 |
DecimalPointCharacterForPrinting <Character> used when printing |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
44 |
DecimalPointCharactersForReading <Collection of Character> accepted as decimalPointChars when reading |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
45 |
|
1295 | 46 |
[author:] |
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
47 |
Claus Gittinger |
1628 | 48 |
|
49 |
[see also:] |
|
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
50 |
Integer LargeInteger SmallInteger |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
51 |
LimitedPrecisionReal Float ShortFloat |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
52 |
Fraction FixedPoint |
88 | 53 |
" |
54 |
! ! |
|
1 | 55 |
|
1892 | 56 |
!Number class methodsFor:'instance creation'! |
1 | 57 |
|
3060 | 58 |
fromString:aString |
59 |
"for compatibility with other smalltalks - same as #readFrom:" |
|
60 |
||
9333 | 61 |
^ self |
62 |
fromString:aString |
|
63 |
decimalPointCharacters:(self decimalPointCharactersForReading) |
|
64 |
||
65 |
" |
|
66 |
Number fromString:'12345' |
|
67 |
Number fromString:'abc' |
|
68 |
Number fromString:'1abc' |
|
69 |
'12345' asNumber |
|
70 |
" |
|
71 |
||
72 |
"Modified: / 3.8.1998 / 20:05:11 / cg" |
|
73 |
! |
|
74 |
||
75 |
fromString:aString decimalPointCharacters:decimalPointCharacters |
|
76 |
"for compatibility with other smalltalks - same as #readFrom:" |
|
77 |
||
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
78 |
|s num| |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
79 |
|
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
80 |
s := aString readStream. |
9333 | 81 |
num := self readFrom:s decimalPointCharacters:decimalPointCharacters onError:[^ self error:'invalid number']. |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
82 |
s atEnd ifFalse:[^ self error:'garbage at end of number']. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
83 |
^ num. |
3060 | 84 |
|
3716 | 85 |
" |
86 |
Number fromString:'12345' |
|
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
87 |
Number fromString:'abc' |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
88 |
Number fromString:'1abc' |
3716 | 89 |
'12345' asNumber |
90 |
" |
|
91 |
||
92 |
"Modified: / 3.8.1998 / 20:05:11 / cg" |
|
3060 | 93 |
! |
94 |
||
9333 | 95 |
fromString:aString decimalPointCharacters:decimalPointCharacters onError:exceptionBlock |
96 |
"for compatibility with other smalltalks - same as #readFrom:" |
|
97 |
||
98 |
^ self readFrom:aString decimalPointCharacters:decimalPointCharacters onError:exceptionBlock |
|
99 |
||
100 |
" |
|
101 |
Number fromString:'12345' onError:0 |
|
102 |
Number fromString:'fooBarBaz' onError:0 |
|
103 |
" |
|
104 |
||
105 |
"Modified: / 3.8.1998 / 20:05:34 / cg" |
|
106 |
! |
|
107 |
||
3060 | 108 |
fromString:aString onError:exceptionBlock |
109 |
"for compatibility with other smalltalks - same as #readFrom:" |
|
110 |
||
111 |
^ self readFrom:aString onError:exceptionBlock |
|
112 |
||
3716 | 113 |
" |
114 |
Number fromString:'12345' onError:0 |
|
115 |
Number fromString:'fooBarBaz' onError:0 |
|
116 |
" |
|
117 |
||
118 |
"Modified: / 3.8.1998 / 20:05:34 / cg" |
|
3060 | 119 |
! |
120 |
||
9333 | 121 |
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters |
122 |
"return the next Number from the (character-)stream aStream; |
|
123 |
skipping all whitespace first; return the value of exceptionBlock, |
|
124 |
if no number can be read. |
|
125 |
This method is less strict than the smalltalk number reader; it |
|
126 |
allows for prefixed + and also allows missing fractional part after eE" |
|
127 |
||
128 |
^ self |
|
129 |
readFrom:aStringOrStream |
|
130 |
decimalPointCharacters:decimalPointCharacters |
|
131 |
onError:[self error:'conversion error for: ' , self name] |
|
132 |
||
133 |
" |
|
134 |
Number readFrom:'123.456' decimalPointCharacters:'.' |
|
135 |
Number readFrom:'123,456' decimalPointCharacters:'.,' |
|
136 |
Number readFrom:'123,456' decimalPointCharacters:'.' |
|
137 |
" |
|
138 |
! |
|
139 |
||
140 |
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters onError:exceptionBlock |
|
1 | 141 |
"return the next Number from the (character-)stream aStream; |
202 | 142 |
skipping all whitespace first; return the value of exceptionBlock, |
7356 | 143 |
if no number can be read. |
144 |
This method is less strict than the smalltalk number reader; it |
|
145 |
allows for prefixed + and also allows missing fractional part after eE" |
|
1 | 146 |
|
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
147 |
^ [ |
9333 | 148 |
|value intValue mantissaAndScale scale decimalMantissa str |
7356 | 149 |
nextChar radix negative signExp exp denom| |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3900
diff
changeset
|
150 |
|
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
151 |
str := aStringOrStream readStream. |
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
152 |
|
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
153 |
nextChar := str skipSeparators. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
154 |
nextChar isNil ifTrue:[^ exceptionBlock value]. |
3 | 155 |
|
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
156 |
(nextChar == $-) ifTrue:[ |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
157 |
negative := true. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
158 |
str next. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
159 |
nextChar := str peekOrNil |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
160 |
] ifFalse:[ |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
161 |
negative := false. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
162 |
(nextChar == $+) ifTrue:[ |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
163 |
str next. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
164 |
nextChar := str peekOrNil |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
165 |
] |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
166 |
]. |
8301 | 167 |
(nextChar isDigit or:[(decimalPointCharacters includes:nextChar)]) ifFalse:[ |
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
168 |
^ exceptionBlock value. |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
169 |
"/ value := super readFrom:str. |
339 | 170 |
"/ negative ifTrue:[value := value negated]. |
171 |
"/ ^ value |
|
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
172 |
]. |
8301 | 173 |
(decimalPointCharacters includes:nextChar) ifTrue:[ |
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
174 |
radix := 10. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
175 |
value := 0.0. |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
176 |
intValue := 0. |
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
177 |
] ifFalse:[ |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
178 |
value := Integer readFrom:str radix:10. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
179 |
nextChar := str peekOrNil. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
180 |
((nextChar == $r) or:[ nextChar == $R]) ifTrue:[ |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
181 |
str next. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
182 |
radix := value. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
183 |
value := Integer readFrom:str radix:radix. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
184 |
] ifFalse:[ |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
185 |
radix := 10 |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
186 |
]. |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
187 |
intValue := value. |
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
188 |
]. |
4637
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4558
diff
changeset
|
189 |
|
8301 | 190 |
(decimalPointCharacters includes:nextChar) ifTrue:[ |
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
191 |
str next. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
192 |
nextChar := str peekOrNil. |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
193 |
decimalMantissa := 0. |
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
194 |
(nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[ |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
195 |
mantissaAndScale := Number readMantissaAndScaleFrom:str radix:radix. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
196 |
value := value asFloat + (mantissaAndScale first). |
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
197 |
nextChar := str peekOrNil |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
198 |
] |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
199 |
]. |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
200 |
('eEdDqQ' includes:nextChar) ifTrue:[ |
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
201 |
str next. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
202 |
nextChar := str peekOrNil. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
203 |
signExp := 1. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
204 |
(nextChar == $+) ifTrue:[ |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
205 |
str next. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
206 |
nextChar := str peekOrNil. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
207 |
] ifFalse:[ |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
208 |
(nextChar == $-) ifTrue:[ |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
209 |
str next. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
210 |
nextChar := str peekOrNil. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
211 |
signExp := -1 |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
212 |
] |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
213 |
]. |
7356 | 214 |
('qQ' includes:nextChar) ifTrue:[ |
215 |
value := value asLongFloat. |
|
216 |
] ifFalse:[ |
|
217 |
value := value asFloat. |
|
218 |
"/ future: (for now, always create Doubles for Dolphin,Squeak etc. compatibility |
|
219 |
"/ ('eE' includes:nextChar) ifTrue:[ |
|
220 |
"/ value := value asShortFloat |
|
221 |
"/ ] |
|
222 |
]. |
|
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
223 |
(nextChar notNil and:[(nextChar isDigitRadix:radix)]) ifTrue:[ |
7356 | 224 |
exp := (Integer readFrom:str radix:radix) * signExp. |
225 |
value := value * ((value class unity * 10.0) raisedToInteger:exp) |
|
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
226 |
] |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
227 |
] ifFalse:[ |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
228 |
('s' includes:nextChar) ifTrue:[ |
9130
07e7a292aa76
fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents:
9127
diff
changeset
|
229 |
str next. |
07e7a292aa76
fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents:
9127
diff
changeset
|
230 |
|
07e7a292aa76
fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents:
9127
diff
changeset
|
231 |
nextChar := str peekOrNil. |
9138 | 232 |
(nextChar notNil and:[ nextChar isDigit]) ifTrue:[ |
233 |
scale := (Integer readFrom:str). |
|
9130
07e7a292aa76
fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents:
9127
diff
changeset
|
234 |
]. |
07e7a292aa76
fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents:
9127
diff
changeset
|
235 |
|
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
236 |
mantissaAndScale isNil ifTrue:[ |
9130
07e7a292aa76
fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents:
9127
diff
changeset
|
237 |
value := intValue asFixedPoint:(scale ? 0). |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
238 |
] ifFalse:[ |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
239 |
denom := 10 raisedTo:mantissaAndScale last. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
240 |
value := FixedPoint |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
241 |
numerator:(intValue * denom) + (mantissaAndScale second) |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
242 |
denominator:denom |
9130
07e7a292aa76
fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents:
9127
diff
changeset
|
243 |
scale:(scale ? mantissaAndScale last). |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
244 |
]. |
7456
42a1cbc55b6c
care to not always return longFloats
Claus Gittinger <cg@exept.de>
parents:
7451
diff
changeset
|
245 |
] ifFalse:[ |
42a1cbc55b6c
care to not always return longFloats
Claus Gittinger <cg@exept.de>
parents:
7451
diff
changeset
|
246 |
value isLimitedPrecisionReal ifTrue:[ |
42a1cbc55b6c
care to not always return longFloats
Claus Gittinger <cg@exept.de>
parents:
7451
diff
changeset
|
247 |
value := value asFloat. |
42a1cbc55b6c
care to not always return longFloats
Claus Gittinger <cg@exept.de>
parents:
7451
diff
changeset
|
248 |
] |
42a1cbc55b6c
care to not always return longFloats
Claus Gittinger <cg@exept.de>
parents:
7451
diff
changeset
|
249 |
]. |
6632
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
250 |
]. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
251 |
negative ifTrue:[ |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
252 |
value := value negated |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
253 |
]. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
254 |
value. |
65014fd967d9
Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6584
diff
changeset
|
255 |
] on:Error do:exceptionBlock |
1 | 256 |
|
329 | 257 |
" |
258 |
Number readFrom:(ReadStream on:'54.32e-01') |
|
259 |
Number readFrom:(ReadStream on:'12345678901234567890') |
|
7356 | 260 |
Number readFrom:(ReadStream on:'12345678901234567890.0') |
261 |
Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890') |
|
329 | 262 |
Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
263 |
Number readFrom:'16rAAAAFFFFAAAAFFFF' |
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
264 |
Number readFrom:'0.000001' |
329 | 265 |
'+00000123.45' asNumber |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
266 |
Number readFrom:'99s' |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
267 |
Number readFrom:'99.00s' |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
268 |
Number readFrom:'99.0000000s' |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
269 |
Number readFrom:'.0000000s' |
7356 | 270 |
Number readFrom:'.0000000q' |
271 |
Number readFrom:'.0000000f' |
|
272 |
Number readFrom:'.0000000e' |
|
273 |
Number readFrom:'.0000000s1' |
|
274 |
Number readFrom:'.0000000q1' |
|
275 |
Number readFrom:'.0000000f1' |
|
276 |
Number readFrom:'.0000000e1' |
|
8301 | 277 |
|
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
278 |
DecimalPointCharactersForReading := #( $. $, ). |
8301 | 279 |
Number readFrom:'99,00' |
280 |
||
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
281 |
DecimalPointCharactersForReading := #( $. ). |
8301 | 282 |
Number readFrom:'99,00' |
329 | 283 |
" |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
284 |
|
3375
7c64da3964e4
faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
285 |
"Modified: / 14.4.1998 / 19:22:50 / cg" |
296 | 286 |
! |
287 |
||
9333 | 288 |
readFrom:aStringOrStream onError:exceptionBlock |
289 |
"return the next Number from the (character-)stream aStream; |
|
290 |
skipping all whitespace first; return the value of exceptionBlock, |
|
291 |
if no number can be read. |
|
292 |
This method is less strict than the smalltalk number reader; it |
|
293 |
allows for prefixed + and also allows missing fractional part after eE" |
|
294 |
||
295 |
^ self |
|
296 |
readFrom:aStringOrStream |
|
297 |
decimalPointCharacters:(self decimalPointCharactersForReading) |
|
298 |
onError:exceptionBlock |
|
299 |
||
300 |
" |
|
301 |
Number readFrom:(ReadStream on:'54.32e-01') |
|
302 |
Number readFrom:(ReadStream on:'12345678901234567890') |
|
303 |
Number readFrom:(ReadStream on:'12345678901234567890.0') |
|
304 |
Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890') |
|
305 |
Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') |
|
306 |
Number readFrom:'16rAAAAFFFFAAAAFFFF' |
|
307 |
Number readFrom:'0.000001' |
|
308 |
'+00000123.45' asNumber |
|
309 |
Number readFrom:'99s' |
|
310 |
Number readFrom:'99.00s' |
|
311 |
Number readFrom:'99.0000000s' |
|
312 |
Number readFrom:'.0000000s' |
|
313 |
Number readFrom:'.0000000q' |
|
314 |
Number readFrom:'.0000000f' |
|
315 |
Number readFrom:'.0000000e' |
|
316 |
Number readFrom:'.0000000s1' |
|
317 |
Number readFrom:'.0000000q1' |
|
318 |
Number readFrom:'.0000000f1' |
|
319 |
Number readFrom:'.0000000e1' |
|
320 |
||
321 |
DecimalPointCharactersForReading := #( $. $, ). |
|
322 |
Number readFrom:'99,00' |
|
323 |
||
324 |
DecimalPointCharactersForReading := #( $. ). |
|
325 |
Number readFrom:'99,00' |
|
326 |
" |
|
327 |
! |
|
328 |
||
296 | 329 |
readSmalltalkSyntaxFrom:aStream |
330 |
"ST-80 compatibility (thanks to a note from alpha testers) |
|
331 |
read and return the next Number in smalltalk syntax from the |
|
7356 | 332 |
(character-) aStream. |
333 |
Returns nil if aStream contains no valid number." |
|
329 | 334 |
|
3613
75629df7f224
fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents:
3394
diff
changeset
|
335 |
^ Scanner scanNumberFrom:aStream |
75629df7f224
fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents:
3394
diff
changeset
|
336 |
"/ ^ Compiler evaluate:aStream compile:false "/ self readFrom:aStream. |
296 | 337 |
|
329 | 338 |
" |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
339 |
Number readSmalltalkSyntaxFrom:'99d' |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
340 |
Number readSmalltalkSyntaxFrom:'99.00d' |
329 | 341 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'54.32e-01') |
342 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'12345678901234567890') |
|
343 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') |
|
344 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'(1/10)') |
|
345 |
Number readFrom:(ReadStream on:'(1/10)') |
|
346 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'+00000123.45') |
|
347 |
Number readFrom:(ReadStream on:'+00000123.45') |
|
5013 | 348 |
|
349 |
|s| |
|
350 |
s := ReadStream on:'2.'. |
|
351 |
Number readSmalltalkSyntaxFrom:s. |
|
352 |
s next |
|
353 |
||
354 |
|s| |
|
355 |
s := ReadStream on:'2.0.'. |
|
356 |
Number readSmalltalkSyntaxFrom:s. |
|
357 |
s next |
|
329 | 358 |
" |
3613
75629df7f224
fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents:
3394
diff
changeset
|
359 |
|
5013 | 360 |
"Modified: / 19.11.1999 / 18:26:47 / cg" |
1 | 361 |
! ! |
701 | 362 |
|
7729
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
363 |
!Number class methodsFor:'constants'! |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
364 |
|
8301 | 365 |
decimalPointCharacter |
366 |
"printed" |
|
367 |
||
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
368 |
<resource: #obsolete> |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
369 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
370 |
^ self decimalPointCharacterForPrinting |
8301 | 371 |
! |
372 |
||
8303 | 373 |
decimalPointCharacter:aCharacter |
374 |
"printed" |
|
375 |
||
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
376 |
<resource: #obsolete> |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
377 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
378 |
self decimalPointCharacterForPrinting:aCharacter |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
379 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
380 |
" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
381 |
1.5 printString |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
382 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
383 |
Number decimalPointCharacter:$,. |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
384 |
1.5 printString |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
385 |
Number decimalPointCharacter:$.. |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
386 |
" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
387 |
! |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
388 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
389 |
decimalPointCharacterForPrinting |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
390 |
"printed" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
391 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
392 |
DecimalPointCharacterForPrinting isNil ifTrue:[ |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
393 |
^ $. |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
394 |
]. |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
395 |
^ DecimalPointCharacterForPrinting |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
396 |
! |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
397 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
398 |
decimalPointCharacterForPrinting:aCharacter |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
399 |
"printed" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
400 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
401 |
DecimalPointCharacterForPrinting := aCharacter |
8303 | 402 |
|
403 |
" |
|
404 |
1.5 printString |
|
405 |
||
9274 | 406 |
Number decimalPointCharacterForPrinting:$,. |
8303 | 407 |
1.5 printString |
9274 | 408 |
Number decimalPointCharacterForPrinting:$.. |
8303 | 409 |
" |
410 |
! |
|
411 |
||
8301 | 412 |
decimalPointCharacters |
413 |
"accepted when converting from a string" |
|
414 |
||
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
415 |
<resource: #obsolete> |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
416 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
417 |
^ self decimalPointCharactersForReading |
8303 | 418 |
|
419 |
" |
|
420 |
1.5 printString |
|
421 |
||
422 |
Number decimalPointCharacters:#( $. $,) . |
|
423 |
Number fromString:'1.5'. |
|
424 |
Number fromString:'1,5'. |
|
425 |
Number decimalPointCharacters:#( $. ). |
|
426 |
" |
|
427 |
! |
|
428 |
||
429 |
decimalPointCharacters:aCollectionOfCharacters |
|
430 |
"accepted when converting from a string" |
|
431 |
||
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
432 |
<resource: #obsolete> |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
433 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
434 |
self decimalPointCharactersForReading:aCollectionOfCharacters |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
435 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
436 |
" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
437 |
Number decimalPointCharacters:#( $. $,) . |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
438 |
Number fromString:'1.5'. |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
439 |
Number fromString:'1,5'. |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
440 |
Number decimalPointCharacters:#( $. ). |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
441 |
" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
442 |
! |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
443 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
444 |
decimalPointCharactersForReading |
9333 | 445 |
"default when converting from a string" |
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
446 |
|
9333 | 447 |
"/ cg: changing the default leads to trouble in some |
448 |
"/ language processors (PrologScanner...) |
|
449 |
"/ PLEASE DO ONLY CHANGE THE DEFAULT BELOW FOR END-USER APPLICATIONS (if at all). |
|
450 |
"/ BETTER: pass the DecimalPointCharacterSet explicitly |
|
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
451 |
DecimalPointCharactersForReading isNil ifTrue:[ |
9333 | 452 |
^ #( $. ) |
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
453 |
]. |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
454 |
^ DecimalPointCharactersForReading |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
455 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
456 |
" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
457 |
1.5 printString |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
458 |
|
9274 | 459 |
Number decimalPointCharactersForReading:#( $. $,) . |
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
460 |
Number fromString:'1.5'. |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
461 |
Number fromString:'1,5'. |
9274 | 462 |
Number decimalPointCharactersForReading:#( $. ). |
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
463 |
" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
464 |
! |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
465 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
466 |
decimalPointCharactersForReading:aCollectionOfCharacters |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
467 |
"accepted when converting from a string" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
468 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
469 |
DecimalPointCharactersForReading := aCollectionOfCharacters |
8303 | 470 |
|
471 |
" |
|
9274 | 472 |
Number decimalPointCharactersForReading:#( $. $,) . |
8303 | 473 |
Number fromString:'1.5'. |
474 |
Number fromString:'1,5'. |
|
9274 | 475 |
Number decimalPointCharactersForReading:#( $. ). |
8303 | 476 |
" |
8301 | 477 |
! |
478 |
||
7729
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
479 |
epsilon |
8634 | 480 |
"return the maximum relative spacing of instances of mySelf |
481 |
(i.e. the value-delta of the least significant bit)" |
|
7729
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
482 |
|
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
483 |
^ self subclassResponsibility |
8844 | 484 |
! |
485 |
||
10727 | 486 |
epsilonForCloseTo |
487 |
"return the epsilon used in the closeTo: comparison. |
|
488 |
(useful would be something like self epsilon or epsilon*10, |
|
489 |
but for Squeak compatibility.... - sigh)" |
|
490 |
||
491 |
^ 0.0001 |
|
492 |
||
493 |
" |
|
494 |
Float epsilon |
|
495 |
ShortFloat epsilon |
|
496 |
Float epsilon10 |
|
497 |
ShortFloat epsilon10 |
|
498 |
" |
|
499 |
! |
|
500 |
||
8844 | 501 |
pi |
502 |
"return Pi in my representation (and accuracy)." |
|
503 |
||
504 |
^ self subclassResponsibility |
|
7729
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
505 |
! ! |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
506 |
|
1892 | 507 |
!Number class methodsFor:'error reporting'! |
701 | 508 |
|
6195 | 509 |
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel arg:arg errorString:text |
3394 | 510 |
"ST-80 compatible signal raising. Provided for PD numeric classes" |
511 |
||
4558 | 512 |
<context: #return> |
513 |
||
6195 | 514 |
^ self |
515 |
raise:aSignalSymbolOrErrorClass |
|
516 |
receiver:someNumber |
|
517 |
selector:sel |
|
518 |
arguments:(Array with:arg) |
|
519 |
errorString:text |
|
3394 | 520 |
|
521 |
" |
|
522 |
Number |
|
6195 | 523 |
raise:#domainErrorSignal |
524 |
receiver:1.0 |
|
525 |
selector:#sin |
|
526 |
arg:nil |
|
527 |
errorString:'foo bar test' |
|
3394 | 528 |
" |
6195 | 529 |
|
530 |
"Modified: / 16.11.2001 / 14:12:50 / cg" |
|
3394 | 531 |
! |
532 |
||
6195 | 533 |
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel arguments:argArray errorString:text |
6194
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
534 |
"ST-80 compatible signal raising. Provided for PD numeric classes. |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
535 |
aSignalSymbolOrErrorClass is either an Error-subclass, or |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
536 |
the selector which is sent to myself, to retrieve the Exception class / Signal." |
701 | 537 |
|
4558 | 538 |
<context: #return> |
539 |
||
6194
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
540 |
|msg signalOrException| |
701 | 541 |
|
542 |
msg := MessageSend |
|
6194
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
543 |
receiver:someNumber |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
544 |
selector:sel |
6195 | 545 |
arguments:argArray. |
3394 | 546 |
|
6194
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
547 |
aSignalSymbolOrErrorClass isSymbol ifTrue:[ |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
548 |
signalOrException := self perform:aSignalSymbolOrErrorClass. |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
549 |
] ifFalse:[ |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
550 |
signalOrException := aSignalSymbolOrErrorClass. "/ assume its an Error-Subclass |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
551 |
]. |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
552 |
|
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
553 |
^ signalOrException |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
554 |
raiseRequestWith:msg |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
555 |
errorString:text |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
556 |
in:thisContext sender |
701 | 557 |
|
558 |
" |
|
3394 | 559 |
Number |
6194
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
560 |
raise:#domainErrorSignal |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
561 |
receiver:1.0 |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
562 |
selector:#foo |
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
563 |
errorString:'foo bar test' |
701 | 564 |
" |
6194
e060dbb4f75c
allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents:
6155
diff
changeset
|
565 |
|
6195 | 566 |
"Modified: / 16.11.2001 / 14:12:09 / cg" |
567 |
! |
|
568 |
||
569 |
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel errorString:text |
|
570 |
"ST-80 compatible signal raising. Provided for PD numeric classes. |
|
571 |
aSignalSymbolOrErrorClass is either an Error-subclass, or |
|
572 |
the selector which is sent to myself, to retrieve the Exception class / Signal." |
|
573 |
||
574 |
<context: #return> |
|
575 |
||
576 |
^ self |
|
577 |
raise:aSignalSymbolOrErrorClass |
|
578 |
receiver:someNumber |
|
579 |
selector:sel |
|
580 |
arguments:#() |
|
581 |
errorString:text |
|
582 |
||
583 |
" |
|
584 |
Number |
|
585 |
raise:#domainErrorSignal |
|
586 |
receiver:1.0 |
|
587 |
selector:#foo |
|
588 |
errorString:'foo bar test' |
|
589 |
" |
|
590 |
||
591 |
"Modified: / 16.11.2001 / 14:13:16 / cg" |
|
701 | 592 |
! ! |
593 |
||
1892 | 594 |
!Number class methodsFor:'private'! |
701 | 595 |
|
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
596 |
readMantissaAndScaleFrom:aStream radix:radix |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
597 |
"helper for readFrom: - |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
598 |
return the mantissa (post-decimal-point digits) from the (character-)stream aStream; |
7356 | 599 |
In addition, the scale (number of postDecimalPoint digits) is returned |
600 |
(to support reading fixedPoint numbers). |
|
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
601 |
No whitespace is skipped. |
7356 | 602 |
Errs if no number is available on aStream." |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
603 |
|
10321
c07d199084fc
avoid double-send of digitValue
Claus Gittinger <cg@exept.de>
parents:
10320
diff
changeset
|
604 |
|nextChar value factor intMantissa scale digit| |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
605 |
|
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
606 |
value := 0.0. |
10320
a573647dad4f
avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents:
10191
diff
changeset
|
607 |
factor := 1.0 / radix. |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
608 |
scale := 0. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
609 |
intMantissa := 0. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
610 |
nextChar := aStream peekOrNil. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
611 |
[nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[ |
10321
c07d199084fc
avoid double-send of digitValue
Claus Gittinger <cg@exept.de>
parents:
10320
diff
changeset
|
612 |
digit := nextChar digitValue. |
c07d199084fc
avoid double-send of digitValue
Claus Gittinger <cg@exept.de>
parents:
10320
diff
changeset
|
613 |
value := value + (digit * factor). |
c07d199084fc
avoid double-send of digitValue
Claus Gittinger <cg@exept.de>
parents:
10320
diff
changeset
|
614 |
intMantissa := (intMantissa * radix) + digit. |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
615 |
factor := factor / radix. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
616 |
scale := scale + 1. |
10320
a573647dad4f
avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents:
10191
diff
changeset
|
617 |
scale > 6 ifTrue:[ |
a573647dad4f
avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents:
10191
diff
changeset
|
618 |
factor := factor asLongFloat. |
a573647dad4f
avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents:
10191
diff
changeset
|
619 |
value := value asLongFloat. |
a573647dad4f
avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents:
10191
diff
changeset
|
620 |
]. |
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
621 |
aStream next. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
622 |
nextChar := aStream peekOrNil |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
623 |
]. |
7388
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
624 |
|
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
625 |
^ (Array with:value with:intMantissa with:scale). |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
626 |
|
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
627 |
" |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
628 |
Number readMantissaAndScaleFrom:'234' readStream radix:10. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
629 |
Number readMantissaAndScaleFrom:'2' readStream radix:10. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
630 |
Number readMantissaAndScaleFrom:'234567' readStream radix:10. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
631 |
Number readMantissaAndScaleFrom:'234000' readStream radix:10. |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
632 |
Number readMantissaAndScaleFrom:'234' readStream radix:10. |
7356 | 633 |
|
634 |
Number readMantissaAndScaleFrom:'12345678901234567890' readStream radix:10. |
|
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
635 |
" |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
636 |
|
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
637 |
"Modified: / 14.4.1998 / 18:47:47 / cg" |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
638 |
! |
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
639 |
|
701 | 640 |
readMantissaFrom:aStream radix:radix |
641 |
"helper for readFrom: - |
|
6692 | 642 |
return the mantissa (post-decimal-point digits) |
643 |
from the (character-)stream aStream; |
|
644 |
No whitespace is skipped. |
|
645 |
Errs if no number available." |
|
701 | 646 |
|
6899
9ed8494c9f10
support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents:
6702
diff
changeset
|
647 |
^ (self readMantissaAndScaleFrom:aStream radix:radix) first |
3375
7c64da3964e4
faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
648 |
|
6692 | 649 |
" |
650 |
Number readMantissaFrom:'234' readStream radix:10. |
|
651 |
Number readMantissaFrom:'2' readStream radix:10. |
|
652 |
Number readMantissaFrom:'234567' readStream radix:10. |
|
653 |
" |
|
654 |
||
3375
7c64da3964e4
faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
655 |
"Modified: / 14.4.1998 / 18:47:47 / cg" |
701 | 656 |
! ! |
657 |
||
8892 | 658 |
!Number class methodsFor:'queries'! |
659 |
||
660 |
isAbstract |
|
11224 | 661 |
"Return if this class is an abstract class. |
662 |
True is returned for Number here; false for subclasses. |
|
663 |
Abstract subclasses must redefine again." |
|
664 |
||
8892 | 665 |
^ self == Number |
666 |
! ! |
|
667 |
||
7261 | 668 |
!Number methodsFor:'Compatibility-Squeak'! |
4988 | 669 |
|
670 |
asSmallAngleDegrees |
|
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
671 |
"Return the receiver normalized to lie within the range (-180, 180)" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
672 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
673 |
| pos | |
4988 | 674 |
|
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
675 |
pos := self \\ 360. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
676 |
pos > 180 ifTrue: [pos := pos - 360]. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
677 |
^ pos |
4988 | 678 |
|
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
679 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
680 |
#(-500 -300 -150 -5 0 5 150 300 500 1200) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
681 |
collect: [:n | n asSmallAngleDegrees] |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
682 |
" |
6072 | 683 |
! |
4988 | 684 |
|
6335
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
685 |
closeFrom:aNumber |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
686 |
"are these two numbers close?" |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
687 |
|
10727 | 688 |
^ self closeFrom:aNumber withEpsilon:(self class epsilonForCloseTo) |
689 |
||
690 |
" |
|
691 |
9.0 closeTo: 8.9999 |
|
692 |
9.9 closeTo: 9 |
|
693 |
(9/3) closeTo: 2.9999 |
|
694 |
1 closeTo: 0.9999 |
|
695 |
1 closeTo: 1.0001 |
|
696 |
1 closeTo: 1.001 |
|
697 |
1 closeTo: 0.999 |
|
698 |
||
699 |
0.9999 closeTo: 1 |
|
700 |
1.0001 closeTo: 1 |
|
701 |
1.001 closeTo: 1 |
|
702 |
0.999 closeTo: 1 |
|
703 |
Float NaN closeTo:Float NaN |
|
704 |
Float infinity closeTo:Float infinity |
|
705 |
" |
|
706 |
! |
|
707 |
||
708 |
closeFrom:aNumber withEpsilon:eps |
|
709 |
"are these two numbers close?" |
|
710 |
||
6335
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
711 |
| fuzz | |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
712 |
|
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
713 |
self isNaN == aNumber isNaN ifFalse: [^ false]. |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
714 |
self isInfinite == aNumber isInfinite ifFalse: [^ false]. |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
715 |
|
10727 | 716 |
fuzz := (self abs max:aNumber abs) * eps. |
6335
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
717 |
^ (self - aNumber) abs <= fuzz |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
718 |
|
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
719 |
" |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
720 |
9.0 closeTo: 8.9999 |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
721 |
9.9 closeTo: 9 |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
722 |
(9/3) closeTo: 2.9999 |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
723 |
1 closeTo: 0.9999 |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
724 |
1 closeTo: 1.0001 |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
725 |
1 closeTo: 1.001 |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
726 |
1 closeTo: 0.999 |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
727 |
|
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
728 |
0.9999 closeTo: 1 |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
729 |
1.0001 closeTo: 1 |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
730 |
1.001 closeTo: 1 |
6345 | 731 |
0.999 closeTo: 1 |
732 |
Float NaN closeTo:Float NaN |
|
733 |
Float infinity closeTo:Float infinity |
|
6335
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
734 |
" |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
735 |
! |
8286bc57d05e
closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents:
6258
diff
changeset
|
736 |
|
6143 | 737 |
closeTo:num |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
738 |
"are these two numbers close to each other?" |
6143 | 739 |
|
10727 | 740 |
^ self closeTo:num withEpsilon:(self class epsilonForCloseTo) |
741 |
||
742 |
" |
|
743 |
1 closeTo:1.0000000001 |
|
744 |
1 closeTo:1.001 |
|
745 |
1 closeTo:1.001 withEpsilon:0.001 |
|
746 |
" |
|
747 |
||
748 |
"Created: / 5.11.2001 / 18:07:26 / cg" |
|
749 |
! |
|
750 |
||
751 |
closeTo:num withEpsilon:eps |
|
752 |
"are these two numbers close to each other?" |
|
753 |
||
6374 | 754 |
num isNumber ifFalse:[^false]. |
10727 | 755 |
^ num closeFrom:self withEpsilon:eps |
6143 | 756 |
|
757 |
" |
|
758 |
1 closeTo:1.0000000001 |
|
759 |
1 closeTo:1.001 |
|
760 |
" |
|
6155 | 761 |
|
762 |
"Created: / 5.11.2001 / 18:07:26 / cg" |
|
6143 | 763 |
! |
764 |
||
9139 | 765 |
degreeCos |
766 |
"Return the cosine of the receiver taken as an angle in degrees." |
|
767 |
||
768 |
^ self degreesToRadians cos |
|
769 |
! |
|
770 |
||
771 |
degreeSin |
|
772 |
"Return the sine of the receiver taken as an angle in degrees." |
|
773 |
||
774 |
^ self degreesToRadians sin |
|
775 |
! |
|
776 |
||
4988 | 777 |
newTileMorphRepresentative |
778 |
^ TileMorph new addArrows; setLiteral: self; addSuffixIfCan |
|
779 |
! |
|
780 |
||
781 |
stringForReadout |
|
782 |
^ self rounded printString |
|
783 |
! ! |
|
784 |
||
9127
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
785 |
!Number methodsFor:'coercing & converting'! |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
786 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
787 |
i |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
788 |
"return a complex number, with the receiver as imaginary part, 0 as real part" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
789 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
790 |
^ Complex |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
791 |
real:0 |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
792 |
imaginary:self |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
793 |
|
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
794 |
" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
795 |
3i |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
796 |
(1+1i) |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
797 |
" |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
798 |
! ! |
04cd80c64a30
decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents:
8979
diff
changeset
|
799 |
|
701 | 800 |
!Number methodsFor:'converting'! |
801 |
||
3634 | 802 |
% aNumber |
803 |
"Return a complex number with the receiver as the real part and |
|
804 |
aNumber as the imaginary part" |
|
805 |
||
806 |
^ Complex real:self imaginary:aNumber |
|
807 |
||
808 |
"Modified: / 9.7.1998 / 10:18:12 / cg" |
|
809 |
! |
|
810 |
||
11458 | 811 |
+/- anError |
812 |
"return a MeasurementValue with the given error." |
|
813 |
||
814 |
^ MeasurementValue value:self minValue:(self-anError) maxValue:(self+anError) |
|
815 |
||
816 |
" |
|
817 |
(100 +/- 5) * 2 |
|
818 |
(100 +/- 5) * (100 +/- 10) |
|
819 |
(100 +/- 5) + (100 +/- 10) |
|
820 |
(100 +/- 5) - (100 +/- 10) |
|
821 |
" |
|
822 |
! |
|
823 |
||
701 | 824 |
@ aNumber |
825 |
"return a Point with the receiver as x-coordinate and the argument |
|
826 |
as y-coordinate" |
|
827 |
||
828 |
%{ /* NOCONTEXT */ |
|
829 |
||
830 |
/* |
|
831 |
* I cannot tell if this special code is worth anything |
|
832 |
*/ |
|
5322 | 833 |
if (__CanDoQuickNew(sizeof(struct __Point))) { /* OBJECT ALLOCATION */ |
7857
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
834 |
OBJ newPoint; |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
835 |
int spc; |
701 | 836 |
|
7857
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
837 |
__qCheckedAlignedNew(newPoint, sizeof(struct __Point)); |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
838 |
__InstPtr(newPoint)->o_class = @global(Point); |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
839 |
__qSTORE(newPoint, @global(Point)); |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
840 |
__PointInstPtr(newPoint)->p_x = self; |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
841 |
__PointInstPtr(newPoint)->p_y = aNumber; |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
842 |
if (! __bothSmallInteger(self, aNumber)) { |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
843 |
spc = __qSpace(newPoint); |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
844 |
__STORE_SPC(newPoint, aNumber, spc); |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
845 |
__STORE_SPC(newPoint, self, spc); |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
846 |
} |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
847 |
RETURN ( newPoint ); |
701 | 848 |
} |
849 |
%} |
|
850 |
. |
|
851 |
^ Point x:self y:aNumber |
|
852 |
! |
|
853 |
||
3634 | 854 |
asComplex |
855 |
"Return a complex number with the receiver as the real part and |
|
856 |
zero as the imaginary part" |
|
857 |
||
7356 | 858 |
^ Complex real:self |
3634 | 859 |
|
860 |
"Modified: / 9.7.1998 / 10:18:16 / cg" |
|
861 |
! |
|
862 |
||
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
863 |
asMetaNumber |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
864 |
^ SomeNumber new realNumber:self |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
865 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
866 |
|
7214 | 867 |
asNumber |
868 |
||
869 |
^ self. |
|
870 |
! |
|
871 |
||
701 | 872 |
asPoint |
873 |
"return a new Point with the receiver as all coordinates; |
|
874 |
often used to supply the same value in two dimensions, as with |
|
875 |
symmetrical gridding or scaling." |
|
876 |
||
877 |
%{ /* NOCONTEXT */ |
|
878 |
||
5322 | 879 |
if (__CanDoQuickNew(sizeof(struct __Point))) { /* OBJECT ALLOCATION */ |
7857
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
880 |
OBJ newPoint; |
701 | 881 |
|
7857
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
882 |
__qCheckedAlignedNew(newPoint, sizeof(struct __Point)); |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
883 |
__InstPtr(newPoint)->o_class = @global(Point); |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
884 |
__qSTORE(newPoint, @global(Point)); |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
885 |
__PointInstPtr(newPoint)->p_x = self; |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
886 |
__PointInstPtr(newPoint)->p_y = self; |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
887 |
__STORE(newPoint, self); |
51971c337c26
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7729
diff
changeset
|
888 |
RETURN ( newPoint ); |
701 | 889 |
} |
890 |
%}. |
|
891 |
^ Point x:self y:self |
|
892 |
! |
|
893 |
||
894 |
degreesToRadians |
|
895 |
"interpreting the receiver as radians, return the degrees" |
|
896 |
||
8203 | 897 |
^ self * (Float pi / 180.0) |
7388
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
898 |
|
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
899 |
" |
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
900 |
180 degreesToRadians |
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
901 |
Float pi radiansToDegrees |
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
902 |
" |
701 | 903 |
! |
904 |
||
905 |
literalArrayEncoding |
|
1245 | 906 |
"encode myself as an array literal, from which a copy of the receiver |
907 |
can be reconstructed with #decodeAsLiteralArray." |
|
701 | 908 |
|
909 |
^ self |
|
910 |
||
911 |
"Modified: 1.9.1995 / 02:25:26 / claus" |
|
1245 | 912 |
"Modified: 22.4.1996 / 13:00:27 / cg" |
701 | 913 |
! |
914 |
||
915 |
radiansToDegrees |
|
916 |
"interpreting the receiver as degrees, return the radians" |
|
917 |
||
8203 | 918 |
^ self * (180.0 / Float pi) |
7388
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
919 |
|
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
920 |
" |
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
921 |
180 degreesToRadians |
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
922 |
Float pi radiansToDegrees |
bb89a53e2682
fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
923 |
" |
6637 | 924 |
! |
925 |
||
926 |
withScale:newScale |
|
8203 | 927 |
"return a fixedPoint number representing the same value as the receiver, |
6637 | 928 |
with newScale number of post-decimal digits" |
929 |
||
930 |
^ self asFixedPoint:newScale |
|
931 |
||
932 |
" |
|
933 |
1234 withScale:2 |
|
934 |
1234.1 withScale:2 |
|
935 |
1234.12 withScale:2 |
|
936 |
1234.123 withScale:2 |
|
937 |
(1/7) withScale:2 |
|
938 |
" |
|
701 | 939 |
! ! |
940 |
||
11008
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
941 |
!Number methodsFor:'converting-times'! |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
942 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
943 |
days |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
944 |
"return a TimeDuration representing this number of days" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
945 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
946 |
^ TimeDuration days:self |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
947 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
948 |
" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
949 |
1000 milliseconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
950 |
10 seconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
951 |
10 minutes |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
952 |
1 days |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
953 |
" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
954 |
! |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
955 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
956 |
hours |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
957 |
"return a TimeDuration representing this number of hours" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
958 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
959 |
^ TimeDuration hours:self |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
960 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
961 |
" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
962 |
1000 milliseconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
963 |
10 seconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
964 |
10 minutes |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
965 |
" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
966 |
! |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
967 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
968 |
milliseconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
969 |
"return a TimeDuration representing this number of milliseconds" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
970 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
971 |
^ TimeDuration fromMilliseconds:self |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
972 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
973 |
" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
974 |
1000 milliseconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
975 |
" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
976 |
! |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
977 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
978 |
minutes |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
979 |
"return a TimeDuration representing this number of minutes" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
980 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
981 |
^ TimeDuration minutes:self |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
982 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
983 |
" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
984 |
1000 milliseconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
985 |
10 seconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
986 |
10 minutes |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
987 |
" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
988 |
! |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
989 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
990 |
seconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
991 |
"return a TimeDuration representing this number of seconds" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
992 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
993 |
^ TimeDuration seconds:self |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
994 |
|
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
995 |
" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
996 |
1000 milliseconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
997 |
10 seconds |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
998 |
" |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
999 |
! ! |
5a92714a522b
timeDuration conversions added
Michael Beyl <mb@exept.de>
parents:
10727
diff
changeset
|
1000 |
|
701 | 1001 |
!Number methodsFor:'intervals'! |
1002 |
||
6072 | 1003 |
downTo:stop |
1004 |
"return an interval from receiver down to the argument, incrementing by -1" |
|
1005 |
||
1006 |
^ self to:stop by:-1 |
|
1007 |
||
1008 |
" |
|
1009 |
(10 downTo:1) do:[:i | Transcript showCR:i]. |
|
1010 |
" |
|
1011 |
! |
|
1012 |
||
701 | 1013 |
to:stop |
1014 |
"return an interval from receiver up to the argument, incrementing by 1" |
|
1015 |
||
1016 |
^ Interval from:self to:stop |
|
1017 |
! |
|
1018 |
||
1019 |
to:stop by:step |
|
1020 |
"return an interval from receiver up to the argument, incrementing by step" |
|
1021 |
||
1022 |
^ Interval from:self to:stop by:step |
|
6154 | 1023 |
! |
1024 |
||
1025 |
to:stop byFactor:factor |
|
1026 |
"return a geometric series from receiver up to the argument; |
|
1027 |
elements have a constant factor in between" |
|
1028 |
||
1029 |
^ GeometricSeries from:self to:stop byFactor:factor |
|
1030 |
||
1031 |
" |
|
1032 |
(1 to:256 byFactor:2) |
|
1033 |
(256 to:1 byFactor:1/2) |
|
1034 |
" |
|
701 | 1035 |
! ! |
1036 |
||
1037 |
!Number methodsFor:'iteration'! |
|
1038 |
||
1039 |
timesRepeat:aBlock |
|
1040 |
"evaluate the argument, aBlock self times" |
|
1041 |
||
1042 |
|count| |
|
1043 |
||
1044 |
count := self. |
|
1045 |
[count > 0] whileTrue:[ |
|
5322 | 1046 |
aBlock value. |
1047 |
count := count - 1 |
|
701 | 1048 |
] |
1049 |
! ! |
|
1050 |
||
3634 | 1051 |
!Number methodsFor:'mathematical functions'! |
1052 |
||
1053 |
conjugated |
|
1054 |
"Return the complex conjugate of this Number." |
|
1055 |
||
1056 |
^ self |
|
1057 |
||
1058 |
"Modified: / 9.7.1998 / 10:17:31 / cg" |
|
1059 |
! |
|
1060 |
||
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1061 |
exp |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1062 |
"compute e**x of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1063 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1064 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1065 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1066 |
^ self asFloat exp. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1067 |
]. |
8634 | 1068 |
^ self exp_withAccuracy:self epsilon |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1069 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1070 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1071 |
floorLog:radix |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1072 |
"return the logarithm truncated as an integer" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1073 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1074 |
^ (self log:radix) floor |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1075 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1076 |
|
3634 | 1077 |
imaginary |
1078 |
"Return the imaginary part of this Number." |
|
1079 |
||
1080 |
^ 0 |
|
1081 |
||
1082 |
"Modified: / 9.7.1998 / 10:17:24 / cg" |
|
1083 |
! |
|
1084 |
||
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1085 |
ln |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1086 |
"compute ln of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1087 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1088 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1089 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1090 |
^ self asFloat ln. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1091 |
]. |
8634 | 1092 |
^ self ln_withAccuracy:self epsilon |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1093 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1094 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1095 |
log |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1096 |
"return log base 10 of the receiver. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1097 |
Alias for log10." |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1098 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1099 |
^ self log10 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1100 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1101 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1102 |
log10 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1103 |
"return log base 10 of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1104 |
|
10550
0f2a07595d1c
Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents:
10325
diff
changeset
|
1105 |
(self isLimitedPrecisionReal not |
0f2a07595d1c
Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents:
10325
diff
changeset
|
1106 |
or:[self generality < 1.0 generality]) ifTrue:[ |
0f2a07595d1c
Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents:
10325
diff
changeset
|
1107 |
^ self asFloat log10. |
0f2a07595d1c
Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents:
10325
diff
changeset
|
1108 |
]. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1109 |
^ self log:10 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1110 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1111 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1112 |
log:aNumber |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1113 |
"return log base aNumber of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1114 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1115 |
^ self ln / aNumber ln |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1116 |
|
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1117 |
" |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1118 |
1000 log:10 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1119 |
(1000 log:10) floor |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1120 |
" |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1121 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1122 |
|
7468
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1123 |
raisedTo:aNumber |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1124 |
"return the receiver raised to aNumber" |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1125 |
|
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1126 |
aNumber = 0 ifTrue:[^ 1]. |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1127 |
aNumber = 1 ifTrue:[^ self]. |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1128 |
aNumber isInteger ifTrue:[ |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1129 |
^ self raisedToInteger:aNumber |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1130 |
]. |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1131 |
^ self asFloat raisedTo:aNumber |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1132 |
|
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1133 |
" |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1134 |
2 raisedTo: 4 |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1135 |
10 raisedTo: 4 |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1136 |
" |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1137 |
! |
61c8a3053bf4
moved math functions to number
Claus Gittinger <cg@exept.de>
parents:
7456
diff
changeset
|
1138 |
|
3634 | 1139 |
real |
1140 |
"Return the real part of this Number." |
|
1141 |
||
1142 |
^ self |
|
1143 |
||
1144 |
"Modified: / 9.7.1998 / 10:17:17 / cg" |
|
6258 | 1145 |
! |
1146 |
||
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1147 |
sqrt |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1148 |
"return the square root of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1149 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1150 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1151 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1152 |
^ self asFloat sqrt. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1153 |
]. |
8634 | 1154 |
^ self sqrt_withAccuracy:self epsilon |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1155 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1156 |
|
10191 | 1157 |
sqrtWithErrorLessThan:epsilon |
1158 |
"compute the square root, using the Newton method. |
|
1159 |
The approximated return value has an error less than the given epsilon." |
|
1160 |
||
1161 |
|y yN| |
|
1162 |
||
1163 |
yN := self / 2. |
|
1164 |
[ |
|
1165 |
y := yN. |
|
1166 |
yN := ( y + (self / y) ) / 2. |
|
1167 |
] doUntil:[ (yN - y) abs < epsilon ]. |
|
1168 |
^ yN. |
|
1169 |
||
1170 |
" |
|
1171 |
(2 asFixedPoint:4) sqrtWithErrorLessThan:0.001 |
|
1172 |
" |
|
1173 |
! |
|
1174 |
||
6258 | 1175 |
timesTwoPower:anInteger |
1176 |
"Return the receiver multiplied by 2.0 raised to the power of the argument. |
|
1177 |
For protocol completeness wrt. Squeak and ST80." |
|
1178 |
||
1179 |
^ self * (2.0 raisedToInteger:anInteger) |
|
1180 |
||
1181 |
" |
|
1182 |
123 timesTwoPower:0 |
|
1183 |
123 timesTwoPower:1 |
|
1184 |
123 timesTwoPower:2 |
|
1185 |
123 timesTwoPower:3 |
|
1186 |
" |
|
3634 | 1187 |
! ! |
1188 |
||
11458 | 1189 |
!Number methodsFor:'measurement values'! |
1190 |
||
1191 |
maxValue |
|
1192 |
"the maximum possible value taking me as a measurement with possible error; |
|
1193 |
as I am exact, thats myself" |
|
1194 |
||
1195 |
^ self |
|
1196 |
! |
|
1197 |
||
1198 |
minValue |
|
1199 |
"the minimum possible value taking me as a measurement with possible error; |
|
1200 |
as I am exact, thats myself" |
|
1201 |
||
1202 |
^ self |
|
1203 |
! ! |
|
1204 |
||
701 | 1205 |
!Number methodsFor:'printing & storing'! |
1206 |
||
5299
92b363dbd833
added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1207 |
printOn:aStream paddedWith:padCharacter to:size base:radix |
92b363dbd833
added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1208 |
|s| |
92b363dbd833
added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1209 |
|
8301 | 1210 |
radix == 10 ifTrue:[ |
1211 |
s := self printString. |
|
1212 |
] ifFalse:[ |
|
1213 |
s := self printStringRadix:radix. |
|
1214 |
]. |
|
5299
92b363dbd833
added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1215 |
s printOn: aStream leftPaddedTo:size with: padCharacter |
11098 | 1216 |
|
1217 |
" |
|
1218 |
100 printOn:Transcript paddedWith:$0 to:10 base:10. Transcript cr. |
|
1219 |
100 printOn:Transcript paddedWith:$0 to:10 base:16. Transcript cr. |
|
1220 |
100 printOn:Transcript paddedWith:(Character space) to:10 base:16. Transcript cr. |
|
1221 |
100 printOn:Transcript paddedWith:(Character space) to:10 base:2. Transcript cr. |
|
1222 |
" |
|
8301 | 1223 |
! |
5299
92b363dbd833
added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1224 |
|
11096
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1225 |
printOn:aStream thousandsSeparator:thousandsSeparator |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1226 |
"print the receiver as business number with thousands separator to aStream. |
11136
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1227 |
thousandsSeparator is locale specific and is usualy a single quote ('), a comma or period." |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1228 |
|
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1229 |
|rest| |
11096
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1230 |
|
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1231 |
self > 999 ifTrue:[ |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1232 |
(self // 1000) printOn:aStream thousandsSeparator:thousandsSeparator. |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1233 |
thousandsSeparator printOn:aStream. |
11136
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1234 |
rest := self \\ 1000. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1235 |
rest < 100 ifTrue:[ |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1236 |
aStream nextPut:$0. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1237 |
rest < 10 ifTrue:[ |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1238 |
aStream nextPut:$0. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1239 |
]. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1240 |
]. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1241 |
rest printOn:aStream. |
11096
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1242 |
^ self. |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1243 |
]. |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1244 |
self printOn:aStream. |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1245 |
|
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1246 |
" |
11097
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1247 |
swiss style: |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1248 |
1000000 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1249 |
12345678 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1250 |
1234567 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1251 |
123456 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
11136
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1252 |
123056 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
11097
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1253 |
12345 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1254 |
1234 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1255 |
123 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1256 |
|
11136
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1257 |
(12345678.12 asFixedPoint:2) printOn:Transcript thousandsSeparator:$'. Transcript cr. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1258 |
1234567.12 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1259 |
123456.12 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1260 |
123056.12 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1261 |
12345.12 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1262 |
1234.12 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1263 |
123.12 printOn:Transcript thousandsSeparator:$'. Transcript cr. |
ac25ee31e086
fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents:
11098
diff
changeset
|
1264 |
|
11097
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1265 |
us style: |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1266 |
1000000 printOn:Transcript thousandsSeparator:$,. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1267 |
12345678 printOn:Transcript thousandsSeparator:$,. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1268 |
1234567 printOn:Transcript thousandsSeparator:$,. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1269 |
123456 printOn:Transcript thousandsSeparator:$,. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1270 |
12345 printOn:Transcript thousandsSeparator:$,. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1271 |
1234 printOn:Transcript thousandsSeparator:$,. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1272 |
123 printOn:Transcript thousandsSeparator:$,. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1273 |
|
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1274 |
german (european ?) style |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1275 |
1000000 printOn:Transcript thousandsSeparator:$.. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1276 |
12345678 printOn:Transcript thousandsSeparator:$.. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1277 |
1234567 printOn:Transcript thousandsSeparator:$.. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1278 |
123456 printOn:Transcript thousandsSeparator:$.. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1279 |
12345 printOn:Transcript thousandsSeparator:$.. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1280 |
1234 printOn:Transcript thousandsSeparator:$.. Transcript cr. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1281 |
123 printOn:Transcript thousandsSeparator:$.. Transcript cr. |
11096
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1282 |
" |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1283 |
! |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1284 |
|
8301 | 1285 |
printStringRadix:radix |
11098 | 1286 |
"only implemented for integers" |
1287 |
||
8301 | 1288 |
self subclassResponsibility |
11098 | 1289 |
|
1290 |
" |
|
1291 |
100 printStringRadix:10. |
|
1292 |
100 printStringRadix:16. |
|
1293 |
100 printStringRadix:2. |
|
1294 |
" |
|
5299
92b363dbd833
added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1295 |
! |
92b363dbd833
added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1296 |
|
11096
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1297 |
printStringWithThousandsSeparator |
11097
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1298 |
"print the receiver as swiss business number with thousands separator to aStream. |
11096
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1299 |
Caveat: Should use the separator from the locale here" |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1300 |
|
11097
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1301 |
^ self printStringWithThousandsSeparator:$'. |
11096
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1302 |
|
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1303 |
" |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1304 |
1000000 printStringWithThousandsSeparator |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1305 |
12345678 printStringWithThousandsSeparator |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1306 |
1234567 printStringWithThousandsSeparator |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1307 |
123456 printStringWithThousandsSeparator |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1308 |
12345 printStringWithThousandsSeparator |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1309 |
1234 printStringWithThousandsSeparator |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1310 |
123 printStringWithThousandsSeparator |
11097
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1311 |
|
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1312 |
1000000 asFixedPoint printStringWithThousandsSeparator |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1313 |
12345678 asFixedPoint printStringWithThousandsSeparator |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1314 |
1234567 asFixedPoint printStringWithThousandsSeparator |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1315 |
123456 asFixedPoint printStringWithThousandsSeparator |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1316 |
12345 asFixedPoint printStringWithThousandsSeparator |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1317 |
1234 asFixedPoint printStringWithThousandsSeparator |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1318 |
123 asFixedPoint printStringWithThousandsSeparator |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1319 |
" |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1320 |
! |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1321 |
|
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1322 |
printStringWithThousandsSeparator:thousandsSeparator |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1323 |
"print the receiver as business number with a thousands separator to aStream. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1324 |
Notice: |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1325 |
americans use comma |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1326 |
germans (europeans ?) use a dot |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1327 |
swiss people (business people ?) use a single quote |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1328 |
|
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1329 |
Caveat: Should use the separator from the locale here" |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1330 |
|
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1331 |
^ String streamContents:[:s | self printOn:s thousandsSeparator:thousandsSeparator]. |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1332 |
|
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1333 |
" |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1334 |
Transcript showCR:(1000000 printStringWithThousandsSeparator:$'). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1335 |
Transcript showCR:(12345678 printStringWithThousandsSeparator:$'). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1336 |
Transcript showCR:(1234567 printStringWithThousandsSeparator:$'). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1337 |
Transcript showCR:(123456 printStringWithThousandsSeparator:$'). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1338 |
Transcript showCR:(12345 printStringWithThousandsSeparator:$'). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1339 |
Transcript showCR:(1234 printStringWithThousandsSeparator:$'). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1340 |
Transcript showCR:(123 printStringWithThousandsSeparator:$'). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1341 |
|
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1342 |
Transcript showCR:(1000000 printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1343 |
Transcript showCR:(12345678 printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1344 |
Transcript showCR:(1234567 printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1345 |
Transcript showCR:(123456 printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1346 |
Transcript showCR:(12345 printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1347 |
Transcript showCR:(1234 printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1348 |
Transcript showCR:(123 printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1349 |
|
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1350 |
Transcript showCR:((1000000 asFixedPoint:2) printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1351 |
Transcript showCR:((12345678 asFixedPoint:2) printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1352 |
Transcript showCR:((1234567 asFixedPoint:2) printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1353 |
Transcript showCR:((123456 asFixedPoint:2) printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1354 |
Transcript showCR:((12345 asFixedPoint:2) printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1355 |
Transcript showCR:((1234 asFixedPoint:2) printStringWithThousandsSeparator:$,). |
5e4961639e41
printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents:
11096
diff
changeset
|
1356 |
Transcript showCR:((123 asFixedPoint:2) printStringWithThousandsSeparator:$,). |
11096
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1357 |
" |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1358 |
! |
19d6c993e67f
printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents:
11008
diff
changeset
|
1359 |
|
701 | 1360 |
storeOn:aStream |
1361 |
"append a string for storing the receiver onto the argument, |
|
1362 |
aStream - since numbers are literals,they store as they print." |
|
1363 |
||
1364 |
^ self printOn:aStream |
|
1365 |
! |
|
1366 |
||
1367 |
storeString |
|
1368 |
"return a string for storing |
|
1369 |
- since numbers are literals, they store as they print." |
|
1370 |
||
1371 |
^ self printString |
|
1372 |
! ! |
|
1373 |
||
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1374 |
!Number methodsFor:'taylor series'! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1375 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1376 |
arcSin_withAccuracy:epsilon |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1377 |
"compute the arcSine of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1378 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1379 |
"/ uses taylor series: |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1380 |
"/ 1*x^3 1*3 * x^5 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1381 |
"/ arcSin = x + ----- + ---------- + ... |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1382 |
"/ 2* 3 2*4 * 5 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1383 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1384 |
|x2 num numf den denf approx delta| |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1385 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1386 |
((self < -1) or:[self > 1]) ifTrue:[ |
8844 | 1387 |
^ self class |
1388 |
raise:#domainErrorSignal |
|
1389 |
receiver:self |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1390 |
selector:#arcSin |
8844 | 1391 |
arguments:#() |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1392 |
errorString:'bad receiver in arcSin' |
8844 | 1393 |
]. |
1394 |
||
1395 |
x2 := self * self. |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1396 |
num := x2 * self. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1397 |
approx := self + (num / 6). |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1398 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1399 |
numf := 3. |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1400 |
denf := 4. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1401 |
den := 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1402 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1403 |
[ |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1404 |
num := (num * x2) * numf. numf := numf + 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1405 |
den := den * denf. denf := denf + 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1406 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1407 |
delta := num / (den * numf). |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1408 |
approx := approx + delta. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1409 |
] doUntil:[delta abs <= epsilon]. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1410 |
^ approx |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1411 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1412 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1413 |
0.5 arcSin 0.523599 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1414 |
0.5q arcSin 0.523598776 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1415 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1416 |
0.5q arcSin_withAccuracy:1 0.520833333 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1417 |
0.5q arcSin_withAccuracy:0.1 0.520833333 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1418 |
0.5q arcSin_withAccuracy:0.01 0.523177083 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1419 |
0.5q arcSin_withAccuracy:0.001 0.523525856 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1420 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1421 |
0.5q arcSin_withAccuracy:1e-20 0.523598776 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1422 |
|
8844 | 1423 |
0.5 asLargeFloat arcSin_withAccuracy:1e-30 -- not yet |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1424 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1425 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1426 |
0.1 arcSin 0.100167 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1427 |
0.1q arcSin 0.100167421 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1428 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1429 |
0.1q arcSin_withAccuracy:1 0.100166667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1430 |
0.1q arcSin_withAccuracy:0.1 0.100166667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1431 |
0.1q arcSin_withAccuracy:0.01 0.100166667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1432 |
0.1q arcSin_withAccuracy:0.001 0.100166667 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1433 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1434 |
0.1q arcSin_withAccuracy:1e-20 0.100167421 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1435 |
|
8844 | 1436 |
0.1 asLargeFloat arcSin_withAccuracy:1e-30 -- not yet |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1437 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1438 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1439 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1440 |
arcTan_withAccuracy:epsilon |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1441 |
"compute the arcTangent of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1442 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1443 |
"/ uses taylor series: |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1444 |
"/ x^3 x^5 x^7 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1445 |
"/ arcTan(x) = x - --- + --- - --- ... |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1446 |
"/ 3 5 7 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1447 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1448 |
|x2 num den approx delta| |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1449 |
|
8844 | 1450 |
x2 := self * self. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1451 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1452 |
num := (x2 * self) negated. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1453 |
den := 3. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1454 |
approx := self + (num / den). |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1455 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1456 |
[ |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1457 |
den := den + 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1458 |
num := (num * x2) negated. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1459 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1460 |
delta := num / den. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1461 |
approx := approx + delta. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1462 |
] doUntil:[delta abs <= epsilon]. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1463 |
^ approx |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1464 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1465 |
" |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1466 |
1.0 arcTan 0.785398 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1467 |
1q arcTan 0.785398163 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1468 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1469 |
1q arcTan_withAccuracy:1 0.666666667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1470 |
1q arcTan_withAccuracy:0.1 0.744011544 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1471 |
1q arcTan_withAccuracy:0.01 0.790299653 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1472 |
1q arcTan_withAccuracy:0.001 0.785897165 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1473 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1474 |
1q arcTan_withAccuracy:1e-8 0.785398168 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1475 |
1q arcTan_withAccuracy:1e-20 -- not yet, converges very slow |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1476 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1477 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1478 |
0.5 arcTan 0.463648 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1479 |
0.5q arcTan 0.463647609 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1480 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1481 |
0.5q arcTan_withAccuracy:1 0.458333333 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1482 |
0.5q arcTan_withAccuracy:0.1 0.458333333 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1483 |
0.5q arcTan_withAccuracy:0.01 0.464583333 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1484 |
0.5q arcTan_withAccuracy:0.001 0.463684276 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1485 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1486 |
0.5q arcTan_withAccuracy:1e-20 0.463647609 |
8844 | 1487 |
0.5 asLargeFloat arcTan_withAccuracy:1e-30 -- not yet |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1488 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1489 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1490 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1491 |
cos_withAccuracy:epsilon |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1492 |
"compute the cosine of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1493 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1494 |
"/ uses taylor series: |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1495 |
"/ x^2 x^4 x^6 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1496 |
"/ cos(x) = 1 - --- + --- - --- ... |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1497 |
"/ 2!! 4!! 6!! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1498 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1499 |
|x2 facN num den approx lastApprox| |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1500 |
|
8844 | 1501 |
x2 := self * self. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1502 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1503 |
num := x2 negated. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1504 |
den := 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1505 |
facN := 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1506 |
approx := 1 + (num / den). |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1507 |
lastApprox := 1. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1508 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1509 |
[ (lastApprox - approx) abs > epsilon ] whileTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1510 |
facN := facN + 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1511 |
den := den * (facN - 1) * facN. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1512 |
num := (num * x2) negated. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1513 |
lastApprox := approx. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1514 |
approx := approx + (num / den). |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1515 |
]. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1516 |
^ approx |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1517 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1518 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1519 |
1.0 cos 0.540302 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1520 |
1.0 asLongFloat cos_withAccuracy:1 0.5 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1521 |
1.0 asLongFloat cos_withAccuracy:0.1 0.541666667 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1522 |
1.0 asLongFloat cos_withAccuracy:0.01 0.540277778 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1523 |
1.0 asLongFloat cos_withAccuracy:0.001 0.540302579 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1524 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1525 |
1.0 asLongFloat cos_withAccuracy:1e-40 0.540302306 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1526 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1527 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1528 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1529 |
cosh_withAccuracy:epsilon |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1530 |
"compute the hyperbolic cosine of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1531 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1532 |
"/ uses taylor series: |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1533 |
"/ x^2 x^4 x^6 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1534 |
"/ cosh = x + --- + --- + --- ... |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1535 |
"/ 2!! 4!! 6!! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1536 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1537 |
|x2 facN num den approx delta| |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1538 |
|
8844 | 1539 |
x2 := self * self. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1540 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1541 |
num := x2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1542 |
den := 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1543 |
facN := 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1544 |
approx := self + (num / den). |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1545 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1546 |
[ |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1547 |
facN := facN + 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1548 |
den := den * (facN - 1) * facN. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1549 |
num := num * x2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1550 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1551 |
delta := num / den. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1552 |
approx := approx + delta. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1553 |
] doUntil:[delta <= epsilon]. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1554 |
^ approx |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1555 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1556 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1557 |
1.0 cosh 1.54308 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1558 |
1.0q cosh_withAccuracy:1 1.5 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1559 |
1.0q cosh_withAccuracy:0.1 1.54308 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1560 |
1.0q cosh_withAccuracy:0.01 1.54308 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1561 |
1.0q cosh_withAccuracy:0.001 1.54308 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1562 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1563 |
1.0q cosh_withAccuracy:1e-40 -> 1.543080 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1564 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1565 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1566 |
|
8634 | 1567 |
epsilon |
1568 |
"return the maximum relative spacing of instances of mySelf |
|
1569 |
(i.e. the value-delta of the least significant bit)" |
|
1570 |
||
1571 |
^ self class epsilon |
|
1572 |
! |
|
1573 |
||
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1574 |
exp_withAccuracy:epsilon |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1575 |
"compute e**x of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1576 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1577 |
"/ uses taylor series: |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1578 |
"/ x x^2 x^3 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1579 |
"/ e^x = 1 + --- + --- + --- ... |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1580 |
"/ 1!! 2!! 3!! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1581 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1582 |
|x2 facN num den approx delta| |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1583 |
|
8844 | 1584 |
x2 := self * self. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1585 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1586 |
num := x2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1587 |
den := 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1588 |
facN := 2. |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1589 |
approx := self + 1 + (num / den). |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1590 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1591 |
[ |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1592 |
facN := facN + 1. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1593 |
den := den * facN. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1594 |
num := num * self. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1595 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1596 |
delta := num / den. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1597 |
approx := approx + delta. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1598 |
] doUntil:[delta abs <= epsilon]. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1599 |
|
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1600 |
^ approx |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1601 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1602 |
" |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1603 |
-1 exp |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1604 |
1.0 exp 2.71828 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1605 |
1q exp 2.71828183 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1606 |
2q exp 7.3890561 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1607 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1608 |
1q exp_withAccuracy:1 2.66666667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1609 |
1q exp_withAccuracy:0.1 2.70833333 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1610 |
1q exp_withAccuracy:0.01 2.71666667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1611 |
1q exp_withAccuracy:0.001 2.71825397 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1612 |
|
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1613 |
2q exp_withAccuracy:LongFloat epsilon 7.3890561 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1614 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1615 |
1.0 asLongFloat exp_withAccuracy:1e-40 2.71828183 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1616 |
|
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1617 |
5 exp_withAccuracy:1e-40 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1618 |
(1 exp_withAccuracy:1e-100) asFixedPoint:100 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1619 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1620 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1621 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1622 |
ln_withAccuracy:epsilon |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1623 |
"compute ln of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1624 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1625 |
"uses taylor series: |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1626 |
u^2 u^3 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1627 |
ln = u - --- + --- ... |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1628 |
2 3 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1629 |
where: |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1630 |
u = x - 1 and: x < 1 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1631 |
|
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1632 |
Now we use modified taylor, which converges faster: |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1633 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1634 |
1+y 1 1 1 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1635 |
ln(x) = ln --- = 2y ( - + - y^2 + - y^4 + ....) |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1636 |
1-y 1 3 5 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1637 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1638 |
where y = (x-1) / (x+1) and x > 0 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1639 |
" |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1640 |
|
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1641 |
|denominator approx y y2 exp delta| |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1642 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1643 |
self <= 0 ifTrue:[ |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1644 |
^ self class |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1645 |
raise:#domainErrorSignal |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1646 |
receiver:self |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1647 |
selector:#ln |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1648 |
arguments:#() |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1649 |
errorString:'bad receiver in ln' |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1650 |
]. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1651 |
|
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1652 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1653 |
y := (self - 1)/(self + 1). |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1654 |
exp := y2 := y * y. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1655 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1656 |
approx := 1. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1657 |
denominator := 3. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1658 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1659 |
[ |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1660 |
delta := exp / denominator. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1661 |
approx := approx + delta. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1662 |
exp := exp * y2. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1663 |
denominator := denominator + 2. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1664 |
] doUntil:[delta <= epsilon]. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1665 |
|
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1666 |
^ y * 2 * approx. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1667 |
|
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1668 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1669 |
" |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1670 |
2.0 ln 0.693147 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1671 |
2.0q ln 0.693147181 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1672 |
|
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1673 |
2.0q ln_withAccuracy:1 0.691358025 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1674 |
2.0q ln_withAccuracy:0.1 0.691358025 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1675 |
2.0q ln_withAccuracy:0.01 0.693004115 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1676 |
2.0q ln_withAccuracy:0.0000001 0.69314718 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1677 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1678 |
2.0q ln_withAccuracy:1e-10 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1679 |
2.0q ln_withAccuracy:1e-20 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1680 |
2.0q ln_withAccuracy:1e-40 0.693147181 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1681 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1682 |
2 ln_withAccuracy:1e-40 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1683 |
0 ln_withAccuracy:1e-40 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1684 |
|
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1685 |
(2 ln_withAccuracy:1e-100) asFixedPoint:100 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1686 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1687 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1688 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1689 |
sin_withAccuracy:epsilon |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1690 |
"compute the sine of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1691 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1692 |
"/ uses taylor series: |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1693 |
"/ x^3 x^5 x^7 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1694 |
"/ sin(x) = x - --- + --- - --- ... |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1695 |
"/ 3!! 5!! 7!! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1696 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1697 |
|x2 facN num den approx delta| |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1698 |
|
8844 | 1699 |
x2 := self * self. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1700 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1701 |
num := (x2 * self) negated. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1702 |
den := 2*3. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1703 |
facN := 3. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1704 |
approx := self + (num / den). |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1705 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1706 |
[ |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1707 |
facN := facN + 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1708 |
den := den * (facN - 1) * facN. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1709 |
num := (num * x2) negated. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1710 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1711 |
delta := num / den. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1712 |
approx := approx + delta. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1713 |
] doUntil:[delta abs <= epsilon]. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1714 |
^ approx |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1715 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1716 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1717 |
1.0 sin 0.841471 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1718 |
1.0q sin 0.841470985 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1719 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1720 |
1.0q sin_withAccuracy:1 0.833333333 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1721 |
1.0q sin_withAccuracy:0.1 0.841666667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1722 |
1.0q sin_withAccuracy:0.01 0.841666667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1723 |
1.0q sin_withAccuracy:0.001 0.841468254 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1724 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1725 |
1.0q sin_withAccuracy:1e-40 0.841470985 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1726 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1727 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1728 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1729 |
sinh_withAccuracy:epsilon |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1730 |
"compute the hyperbolic sine of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1731 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1732 |
"/ uses taylor series: |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1733 |
"/ x^3 x^5 x^7 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1734 |
"/ sinh(x) = x + --- + --- + --- ... |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1735 |
"/ 3!! 5!! 7!! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1736 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1737 |
|x2 facN num den approx delta| |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1738 |
|
8844 | 1739 |
x2 := self * self. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1740 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1741 |
num := x2 * self. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1742 |
den := 2*3. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1743 |
facN := 3. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1744 |
approx := self + (num / den). |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1745 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1746 |
[ |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1747 |
facN := facN + 2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1748 |
den := den * (facN - 1) * facN. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1749 |
num := num * x2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1750 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1751 |
delta := num / den. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1752 |
approx := approx + delta. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1753 |
] doUntil:[delta abs <= epsilon]. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1754 |
^ approx |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1755 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1756 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1757 |
1.0 sinh 1.1752 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1758 |
1q sinh 1.17520119 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1759 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1760 |
1q sinh_withAccuracy:1 1.16666667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1761 |
1q sinh_withAccuracy:0.1 1.175 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1762 |
1q sinh_withAccuracy:0.01 1.175 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1763 |
1q sinh_withAccuracy:0.001 1.17519841 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1764 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1765 |
1q sinh_withAccuracy:1e-40 1.17520119 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1766 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1767 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1768 |
|
7729
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1769 |
sqrt_withAccuracy:epsilon |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1770 |
"compute square root of the receiver" |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1771 |
" |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1772 |
Use the Heron Algorithm: |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1773 |
|
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1774 |
x_n + (a / x_n) |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1775 |
x_n+1 = --------------- |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1776 |
2 |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1777 |
|
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1778 |
sqrt(a) = x_n |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1779 |
" |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1780 |
|
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1781 |
|approx| |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1782 |
|
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1783 |
self <= 0 ifTrue:[ |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1784 |
self = 0 ifTrue:[ |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1785 |
^ self |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1786 |
]. |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1787 |
^ self class |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1788 |
raise:#imaginaryResultSignal |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1789 |
receiver:self |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1790 |
selector:#sqrt |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1791 |
arguments:#() |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1792 |
errorString:'bad (negative) receiver in sqrt' |
7729
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1793 |
]. |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1794 |
|
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1795 |
approx := 1. |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1796 |
[ |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1797 |
|lastApprox| |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1798 |
|
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1799 |
lastApprox := approx. |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1800 |
approx := ((self / approx) + approx) / 2. |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1801 |
(approx - lastApprox) abs > epsilon |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1802 |
] whileTrue. |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1803 |
^ approx |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1804 |
|
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1805 |
" |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1806 |
2 sqrt 1.41421 |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1807 |
2q sqrt_withAccuracy:0.01 1.41666667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1808 |
2q sqrt_withAccuracy:0.0001 1.41421569 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1809 |
2q sqrt_withAccuracy:0.0000001 1.41421356 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1810 |
2q sqrt_withAccuracy:0.0000000001 1.41421356 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1811 |
2q sqrt_withAccuracy:0.000000000001 1.41421356 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1812 |
2q sqrt_withAccuracy:LongFloat epsilon 1.41421356 |
7729
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1813 |
|
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1814 |
(4 sqrt_withAccuracy:Integer epsilon) asFloat |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1815 |
|
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1816 |
MessageTally spyOn:[ |arg| |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1817 |
arg := 2 asLongFloat. |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1818 |
1000000 timesRepeat:[ |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1819 |
arg sqrt_withAccuracy:0.000000000001 |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1820 |
] |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1821 |
] |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1822 |
Time millisecondsToRun:[ |arg| |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1823 |
arg := 2 asLongFloat. |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1824 |
1000000 timesRepeat:[ |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1825 |
arg sqrt_withAccuracy:0.000000000001 |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1826 |
] |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1827 |
] |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1828 |
" |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1829 |
! |
bbd20db09d1b
Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents:
7468
diff
changeset
|
1830 |
|
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1831 |
tan_withAccuracy:epsilon |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1832 |
"compute the tangens of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1833 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1834 |
"/ uses taylor series: |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1835 |
"/ x^3 x^5 x^7 x^9 2^2n * ( 2^2n - 1) * B2n * x^(2n-1) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1836 |
"/ tan = x + 1*--- + 2*--- + 17*--- + 62*----... ----------------------------------... |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1837 |
"/ 3 15 315 2835 (2n)!! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1838 |
"/ where Bi is the ith bernoulli number. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1839 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1840 |
|factors idx x2 num t approx lastApprox delta| |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1841 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1842 |
"/ (1 to:20) collect:[:n| |num den| |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1843 |
"/ num := (2 raisedTo:(2*n)) * ((2 raisedTo:(2*n))-1) * ((n*2) bernoulli). |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1844 |
"/ den := (2*n) factorial. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1845 |
"/ num / den |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1846 |
"/ ] |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1847 |
factors := #( |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1848 |
(1 3) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1849 |
(2 15) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1850 |
(17 315) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1851 |
(62 2835) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1852 |
(1382 155925) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1853 |
(21844 6081075) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1854 |
(929569 638512875) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1855 |
(6404582 10854718875) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1856 |
(443861162 1856156927625) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1857 |
(18888466084 194896477400625) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1858 |
(113927491862 2900518163668125) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1859 |
(58870668456604 3698160658676859375) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1860 |
(8374643517010684 1298054391195577640625) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1861 |
(689005380505609448 263505041412702261046875) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1862 |
(129848163681107301953 122529844256906551386796875) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1863 |
(1736640792209901647222 4043484860477916195764296875) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1864 |
(418781231495293038913922 2405873491984360136479756640625) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1865 |
(56518638202982204522669764 801155872830791925447758961328125) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1866 |
(32207686319158956594455462 1126482925555250126673224649609375)). |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1867 |
|
8844 | 1868 |
x2 := self * self. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1869 |
|
8203 | 1870 |
num := x2 * self. "/ = x^3 |
1871 |
approx := self + (num / 3). "/ do the first iteration |
|
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1872 |
lastApprox := self. |
8203 | 1873 |
idx := 2. |
1874 |
[ |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1875 |
t := factors at:idx ifAbsent:[]. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1876 |
t isNil ifTrue:[ |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1877 |
self error:'too many iterations'. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1878 |
"/ Not enough bernoulli numbers for now... |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1879 |
"/ |tempNum tempDen| |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1880 |
"/ tempNum := 2 raisedTo:(2*idx). |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1881 |
"/ tempNum := tempNum * (tempNum-1) * ((2*idx) bernoulli). |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1882 |
"/ tempDen := (2*idx) factorial. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1883 |
"/ t := Array with:tempNum with:tempDen. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1884 |
]. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1885 |
idx := idx + 1. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1886 |
num := num * x2. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1887 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1888 |
delta := num * t first / t second. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1889 |
approx := approx + delta. |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1890 |
] doUntil:[delta abs <= epsilon]. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1891 |
^ approx |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1892 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1893 |
" |
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1894 |
0.5 tan 0.546302 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1895 |
0.5q tan 0.54630249 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1896 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1897 |
0.5q tan_withAccuracy:1 0.541666667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1898 |
0.5q tan_withAccuracy:0.1 0.541666667 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1899 |
0.5q tan_withAccuracy:0.01 0.545833333 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1900 |
0.5q tan_withAccuracy:0.001 0.54625496 |
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1901 |
0.5q tan_withAccuracy:1e-15 0.54630249 |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1902 |
|
10556
fb4ea1df1f1d
Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents:
10550
diff
changeset
|
1903 |
0.5q tan_withAccuracy:1e-40 -- too many iterations |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1904 |
" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1905 |
! ! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1906 |
|
701 | 1907 |
!Number methodsFor:'testing'! |
1908 |
||
5360 | 1909 |
isDivisibleBy:aNumber |
1910 |
"return true, if the receiver can be divided by the argument, aNumber without a remainder. |
|
1911 |
Notice, that the result is only worth trusting, if the receiver is an integer." |
|
1912 |
||
1913 |
aNumber = 0 ifTrue: [^ false]. |
|
1914 |
aNumber isInteger ifFalse: [^ false]. |
|
1915 |
^ (self \\ aNumber) = 0 |
|
1916 |
||
1917 |
" |
|
1918 |
3 isDivisibleBy:2 |
|
1919 |
4 isDivisibleBy:2 |
|
1920 |
4.0 isDivisibleBy:2 |
|
1921 |
4.5 isDivisibleBy:4.5 |
|
1922 |
4.5 isDivisibleBy:1.0 |
|
1923 |
" |
|
1924 |
! |
|
1925 |
||
6143 | 1926 |
isNaN |
1927 |
"return true, if the receiver is an invalid float (NaN - not a number)." |
|
1928 |
||
1929 |
^ false |
|
6155 | 1930 |
|
1931 |
"Created: / 5.11.2001 / 18:07:26 / cg" |
|
6143 | 1932 |
! |
1933 |
||
701 | 1934 |
isNumber |
1935 |
"return true, if the receiver is a kind of number" |
|
1936 |
||
1937 |
^ true |
|
1938 |
! |
|
1939 |
||
6087 | 1940 |
isReal |
1941 |
"return true, if the receiver is some kind of real number (as opposed to a complex); |
|
1942 |
true is returned here - the method is redefined from Object." |
|
1943 |
||
1944 |
^ true |
|
1945 |
! |
|
1946 |
||
701 | 1947 |
isZero |
1557 | 1948 |
"return true, if the receiver is zero" |
1949 |
||
701 | 1950 |
^ self = 0 |
1557 | 1951 |
|
1952 |
"Modified: 18.7.1996 / 12:40:49 / cg" |
|
701 | 1953 |
! ! |
1954 |
||
4659
cdf37afc0e26
moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents:
4637
diff
changeset
|
1955 |
!Number methodsFor:'tracing'! |
cdf37afc0e26
moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents:
4637
diff
changeset
|
1956 |
|
4682 | 1957 |
traceInto:aRequestor level:level from:referrer |
4659
cdf37afc0e26
moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents:
4637
diff
changeset
|
1958 |
"double dispatch into tracer, passing my type implicitely in the selector" |
cdf37afc0e26
moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents:
4637
diff
changeset
|
1959 |
|
4682 | 1960 |
^ aRequestor traceNumber:self level:level from:referrer |
4659
cdf37afc0e26
moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents:
4637
diff
changeset
|
1961 |
|
cdf37afc0e26
moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents:
4637
diff
changeset
|
1962 |
|
cdf37afc0e26
moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents:
4637
diff
changeset
|
1963 |
! ! |
cdf37afc0e26
moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents:
4637
diff
changeset
|
1964 |
|
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1965 |
!Number methodsFor:'trigonometric'! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1966 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1967 |
arcCos |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1968 |
"return the arccosine of the receiver (in radians)" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1969 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1970 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1971 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1972 |
^ self asFloat arcCos. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1973 |
]. |
8844 | 1974 |
^ (self class pi / 2) - self arcSin |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1975 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1976 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1977 |
arcCosh |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1978 |
"return the hyperbolic arccosine of the receiver." |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1979 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1980 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1981 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1982 |
^ self asFloat arcCosh. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1983 |
]. |
8844 | 1984 |
^ (self + (self*self-1) sqrt) ln. |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1985 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1986 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1987 |
arcSin |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1988 |
"return the arcsine of the receiver (in radians)" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1989 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1990 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1991 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1992 |
^ self asFloat arcSin. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1993 |
]. |
8634 | 1994 |
^ self arcSin_withAccuracy:self epsilon |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1995 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1996 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1997 |
arcSinh |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1998 |
"return the hyperbolic arcsine of the receiver." |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
1999 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2000 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2001 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2002 |
^ self asFloat arcSinh. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2003 |
]. |
8844 | 2004 |
^ ( self + (self*self+1) sqrt ) ln |
2005 |
"/ ^ self arcSinh_withAccuracy:self epsilon |
|
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2006 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2007 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2008 |
arcTan |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2009 |
"return the arctangent of the receiver (as radians)" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2010 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2011 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2012 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2013 |
^ self asFloat arcTan. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2014 |
]. |
8634 | 2015 |
^ self arcTan_withAccuracy:self epsilon |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2016 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2017 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2018 |
arcTanh |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2019 |
"return the hyperbolic arctangent of the receiver." |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2020 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2021 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2022 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2023 |
^ self asFloat arcTanh. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2024 |
]. |
8844 | 2025 |
^ ((self + 1) ln / 2) - ((1 - self) ln / 2) |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2026 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2027 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2028 |
cos |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2029 |
"return the cosine of the receiver (interpreted as radians)" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2030 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2031 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2032 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2033 |
^ self asFloat cos. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2034 |
]. |
8634 | 2035 |
^ self cos_withAccuracy:self epsilon |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2036 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2037 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2038 |
cosh |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2039 |
"return the hyperbolic cosine of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2040 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2041 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2042 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2043 |
^ self asFloat cosh. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2044 |
]. |
8634 | 2045 |
^ self cosh_withAccuracy:self epsilon |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2046 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2047 |
|
8844 | 2048 |
cot |
2049 |
"return the cotangent of the receiver" |
|
2050 |
||
2051 |
^ 1 / self tan |
|
2052 |
! |
|
2053 |
||
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2054 |
sin |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2055 |
"return the sine of the receiver (interpreted as radians)" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2056 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2057 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2058 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2059 |
^ self asFloat sin. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2060 |
]. |
8634 | 2061 |
^ self sin_withAccuracy:self epsilon |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2062 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2063 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2064 |
sinh |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2065 |
"return the hyperbolic sine of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2066 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2067 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2068 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2069 |
^ self asFloat sinh. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2070 |
]. |
8634 | 2071 |
^ self sinh_withAccuracy:self epsilon |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2072 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2073 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2074 |
tan |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2075 |
"return the tangens of the receiver (interpreted as radians)" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2076 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2077 |
^ self sin / self cos |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2078 |
! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2079 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2080 |
tanh |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2081 |
"return the hyperbolic tangens of the receiver" |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2082 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2083 |
(self isLimitedPrecisionReal not |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2084 |
or:[self generality < 1.0 generality]) ifTrue:[ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2085 |
^ self asFloat tanh. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2086 |
]. |
8634 | 2087 |
^ self tanh_withAccuracy:self epsilon |
7449
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2088 |
|
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2089 |
"/ If a fast exp is available, the following might be better... |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2090 |
"/ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2091 |
"/ |exp nexp| |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2092 |
"/ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2093 |
"/ "/ tanh is: |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2094 |
"/ "/ sinh(x) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2095 |
"/ "/ ------- |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2096 |
"/ "/ cosh(x) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2097 |
"/ "/ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2098 |
"/ "/ which is: |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2099 |
"/ "/ (exp(x) - exp(-x)) / 2 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2100 |
"/ "/ ---------------------- |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2101 |
"/ "/ (exp(x) + exp(-x)) / 2 |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2102 |
"/ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2103 |
"/ exp := self exp. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2104 |
"/ nexp := self negated exp. |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2105 |
"/ |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2106 |
"/ ^ (exp - nexp) / (exp + nexp) |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2107 |
! ! |
192789c6e1c2
fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents:
7388
diff
changeset
|
2108 |
|
5552 | 2109 |
!Number methodsFor:'truncation & rounding'! |
3900
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2110 |
|
4895 | 2111 |
detentBy: detent atMultiplesOf: grid snap: snap |
2112 |
"Map all values that are within detent/2 of any multiple of grid |
|
2113 |
to that multiple. |
|
2114 |
Otherwise, if snap is true, return self, meaning that the values |
|
2115 |
in the dead zone will never be returned. |
|
2116 |
If snap is false, then expand the range between dead zones |
|
2117 |
so that it covers the range between multiples of the grid, |
|
2118 |
and scale the value by that factor." |
|
2119 |
||
2120 |
| r1 r2 | |
|
2121 |
||
2122 |
r1 := self roundTo: grid. "Nearest multiple of grid" |
|
2123 |
(self roundTo: detent) = r1 ifTrue: [^ r1]. "Snap to that multiple..." |
|
2124 |
snap ifTrue: [^ self]. "...or return self" |
|
2125 |
||
2126 |
r2 := self < r1 "Nearest end of dead zone" |
|
5322 | 2127 |
ifTrue: [r1 - (detent asFloat/2)] |
2128 |
ifFalse: [r1 + (detent asFloat/2)]. |
|
4895 | 2129 |
|
2130 |
"Scale values between dead zones to fill range between multiples" |
|
2131 |
^ r1 + ((self - r2) * grid asFloat / (grid - detent)) |
|
2132 |
||
2133 |
" |
|
2134 |
(170 to: 190 by: 2) collect: [:a | a detentBy: 10 atMultiplesOf: 90 snap: true] |
|
2135 |
(170 to: 190 by: 2) collect: [:a | a detentBy: 10 atMultiplesOf: 90 snap: false] |
|
2136 |
(3.9 to: 4.1 by: 0.02) collect: [:a | a detentBy: 0.1 atMultiplesOf: 1.0 snap: true] |
|
2137 |
(-3.9 to: -4.1 by: -0.02) collect: [:a | a detentBy: 0.1 atMultiplesOf: 1.0 snap: false] |
|
2138 |
" |
|
2139 |
! |
|
2140 |
||
3900
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2141 |
fractionPart |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2142 |
"return a float with value from digits after the decimal point. |
7356 | 2143 |
i.e. the receiver minus its truncated value, |
2144 |
such that (self truncated + self fractionPart) = self" |
|
3900
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2145 |
|
7356 | 2146 |
^ self - self truncated |
3900
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2147 |
|
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2148 |
" |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2149 |
1234.56789 fractionPart |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2150 |
1.2345e6 fractionPart |
7356 | 2151 |
|
2152 |
1.6 asLongFloat fractionPart + 1.6 asLongFloat truncated |
|
2153 |
-1.6 asLongFloat fractionPart + -1.6 asLongFloat truncated |
|
3900
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2154 |
" |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2155 |
|
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2156 |
"Modified: / 4.11.1996 / 20:26:54 / cg" |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2157 |
"Created: / 28.10.1998 / 17:14:40 / cg" |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2158 |
! |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2159 |
|
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2160 |
integerPart |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2161 |
"return a float with value from digits before the decimal point |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2162 |
(i.e. the truncated value)" |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2163 |
|
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2164 |
^ self truncated asFloat |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2165 |
|
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2166 |
" |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2167 |
1234.56789 integerPart |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2168 |
1.2345e6 integerPart |
6154 | 2169 |
12.5 integerPart |
2170 |
-12.5 integerPart |
|
2171 |
(5/3) integerPart |
|
2172 |
(-5/3) integerPart |
|
2173 |
(5/3) truncated |
|
2174 |
(-5/3) truncated |
|
3900
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2175 |
" |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2176 |
|
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2177 |
"Created: / 28.10.1998 / 17:14:56 / cg" |
6154 | 2178 |
"Modified: / 5.11.2001 / 17:54:22 / cg" |
3900
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2179 |
! ! |
c3bc76767cfc
added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3770
diff
changeset
|
2180 |
|
1892 | 2181 |
!Number class methodsFor:'documentation'! |
701 | 2182 |
|
2183 |
version |
|
11458 | 2184 |
^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.118 2009-01-14 22:06:10 cg Exp $' |
701 | 2185 |
! ! |