145 |
145 |
146 ^ (self - ((self / aNumber) floor * aNumber)) floor asInteger |
146 ^ (self - ((self / aNumber) floor * aNumber)) floor asInteger |
147 ! ! |
147 ! ! |
148 |
148 |
149 !LimitedPrecisionReal methodsFor:'coercion and converting'! |
149 !LimitedPrecisionReal methodsFor:'coercion and converting'! |
|
150 |
|
151 asFixedPoint |
|
152 "return the receiver as fixedPoint number. |
|
153 Q: what should the scale be here ?" |
|
154 |
|
155 ^ self asFraction asFixedPoint |
|
156 |
|
157 " |
|
158 0.3 asFixedPoint |
|
159 0.5 asFixedPoint |
|
160 (1/5) asFloat asFixedPoint |
|
161 (1/3) asFloat asFixedPoint |
|
162 (2/3) asFloat asFixedPoint |
|
163 (1/8) asFloat asFixedPoint |
|
164 3.14159 asFixedPoint |
|
165 " |
|
166 |
|
167 "Modified: 10.1.1997 / 19:59:56 / cg" |
|
168 ! |
|
169 |
|
170 asFixedPoint:scale |
|
171 "return the receiver as fixedPoint number with the given |
|
172 number of post-decimal-digits." |
|
173 |
|
174 ^ self asFraction asFixedPoint:scale |
|
175 |
|
176 " |
|
177 0.3 asFixedPoint:3 |
|
178 0.5 asFixedPoint:3 |
|
179 (1/5) asFloat asFixedPoint:1 |
|
180 (1/8) asFloat asFixedPoint:1 |
|
181 3.14159 asFixedPoint:2 |
|
182 3.14159 asFixedPoint:3 |
|
183 (3.14159 asFixedPoint:2) asFixedPoint:5 |
|
184 " |
|
185 |
|
186 "Modified: 10.1.1997 / 19:59:42 / cg" |
|
187 ! |
150 |
188 |
151 asFraction |
189 asFraction |
152 "return a corresponding fraction |
190 "return a corresponding fraction |
153 - notice, that 'aFract asFloat asFraction' does not always return |
191 - notice, that 'aFract asFloat asFraction' does not always return |
154 a good fraction ... due to rounding errors when converting to float" |
192 a good fraction ... due to rounding errors when converting to float" |