|
Class: ArithmeticValue
Object
|
+--Magnitude
|
+--ArithmeticValue
|
+--MeasurementValue
|
+--Number
|
+--Point
- Package:
- stx:libbasic
- Category:
- Magnitude-Numbers
- Version:
- rev:
1.220
date: 2024/01/09 14:46:20
- user: cg
- file: ArithmeticValue.st directory: libbasic
- module: stx stc-classLibrary: libbasic
ArithmeticValue is an abstract superclass for all things responding to
arithmetic messages. It was inserted into the hierarchy, to allow objects
like matrices, functions etc. to share the arithmetic methods defined here.
Notice, that what used to be signals are now exception classes - the class
variables and signal accessors remain here for backward compatibility.
[class variables:]
ArithmeticSignal <Error> parent of all arithmetic signals
(never raised itself)
New: now a reference to ArithmeticError
DomainErrorSignal <Error> raised upon float errors
(for example range in trigonometric)
New: now a reference to DomainError; no longer a classVar
DivisionByZeroSignal <Error> raised when division by 0 is attempted
New: now a reference to ZeroDivide
OverflowSignal <Error> raised on overflow/underflow conditions
UnderflowSignal in float arithmetic.
Notice: some OperatingSystems do not
provide enough information for ST/X to
extract the real reason for the floatException
thus raising DomainErrorSignal in these cases.
copyrightCOPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
Compatibility-VW
-
nan
-
VW compatibility
Signal constants
-
arithmeticSignal
-
return the parent of all arithmetic signals.
This now returns ArithmeticError (class based exception)
and this method is only provided for portability
(old Smalltalk versions used a signal instance here).
You can savely use ArithmeticError directly.
-
coercionErrorSignal
-
obsolete
-
divisionByZeroSignal
-
return the signal which is raised on division by zero.
No longer used - we now have the class based ZeroDivide exception.
This method is kept for backward compatibility.
-
domainErrorSignal
-
return the signal which is raised on some math errors,
when the argument is outside the legal domain.
(such as arcSin of 2 etc.)
This now returns DomainError (class based exception)
and this method is only provided for portability
(old Smalltalk versions used a signal instance here).
You can savely use DomainError directly.
-
imaginaryResultSignal
-
return the signal which is raised when an imaginary result would be created
(such as when taking the sqrt of a negative number).
This error can be handled by wrapping the computation inside a trapImaginary
block; then, a complex result is generated.
-
infiniteResultSignal
-
return the signal which is raised when an infinite result would be created.
This is a subclass of DomainError.
(such as when taking the logarithm of zero)
-
operationNotPossibleSignal
-
-
overflowSignal
-
return the signal which is raised on overflow conditions (in floats).
Attention: currently not raised on all architectures; some return NaN
-
rangeErrorSignal
-
return the parent of the overflow/underflow signals.
This now returns RangeError (class based exception)
and this method is only provided for portability
(old Smalltalk versions used a signal instance here).
You can savely use RangeError directly.
-
undefinedResultSignal
-
-
underflowSignal
-
return the signal which is raised on underflow conditions (in floats)
Attention: currently not raised on all architectures; some return zero
-
unorderedSignal
-
return the signal which is raised when numbers are compared,
for which no ordering is defined (for example: complex numbers).
This now returns UnorderedNumbersError (class based exception)
and this method is only provided for portability
(old Smalltalk versions used a signal instance here).
You can savely use UnorderedNumbersError directly.
class initialization
-
initialize
-
setup the signals
-
raiseNaNExceptions
-
this boolean controls if operations with nan should raise an
exception or not.
If not, another nan is returned from such operations.
Does not really work in all situations (need checks in inline C code)
-
raiseNaNExceptions: aBoolean
-
this boolean controls if operations with nan should raise an
exception or not.
If not, another nan is returned from such operations.
Does not really work in all situations (need checks in inline C code)
-
raiseOutOfRangeExceptions
-
this boolean controls if float conversions should raise an
exception if the converted value is out of range, or not.
If not, infinity is returned from such operations
-
raiseOutOfRangeExceptions: aBoolean
-
this boolean controls if float conversions should raise an
exception if the converted value is out of range, or not.
If not, infinity is returned from such operations
coercing & converting
-
coerce: aNumber
-
convert the argument aNumber into an instance of the receiver (class) and return it.
** This method must be redefined in concrete classes (subclassResponsibility) **
-
generality
-
return a number giving the receiver's generality.
That number is used to convert one of the arguments in a mixed expression.
The generality has to be defined in subclasses,
such that gen(a) > gen(b) iff, conversion of b into a's class
does not cut precision.
For example, Integer has 40, Float has 80, meaning that if we convert a Float to an Integer,
some precision may be lost.
The generality is used by ArithmeticValue>>retry:coercing:,
which converts the lower-precision number to the higher precision
number's class, when mixed-type arithmetic is performed.
** This method must be redefined in concrete classes (subclassResponsibility) **
constants
-
NaN
-
return the constant NaN (not a Number).
-
infinity
-
return something which represents positive infinity.
Warning: do not compare equal against infinities;
instead, check using isFinite or isInfinite
-
negativeInfinity
-
return something which represents negative infinity.
Warning: do not compare equal against infinities;
instead, check using isFinite or isInfinite
-
one
-
return something which represents the one element (for my instances).
That is the neutral element for multiplication.
-
positiveInfinity
-
return something which represents positive infinity.
Warning: do not compare equal against infinities;
instead, check using isFinite or isInfinite
-
powersOfTen
-
return a table with powers of ten (1..)
Usage example(s):
-
powersOfTenth
-
return a table with reciprocals of powers of ten (-1..)
Usage example(s):
-
tenRaisedToInteger: int
-
return a power of ten;
Used often, so we use a table
Usage example(s):
Number tenRaisedToInteger:-2
Number tenRaisedToInteger:-1
Number tenRaisedToInteger:1
Number tenRaisedToInteger:10
Number tenRaisedToInteger:100
|
-
unity
-
return something which represents the unity element (for my instances).
That is the neutral element for multiplication.
-
zero
-
return something which represents the zero element (for my instances).
That is the neutral element for addition.
Usage example(s):
assume that all of my subclasses know how to add zero
|
error reporting
-
raise: aSignalSymbolOrErrorClass receiver: someNumber selector: sel arguments: argArray errorString: text
-
ST-80 compatible signal raising. Provided for PD numeric classes.
aSignalSymbolOrErrorClass is either an Error-subclass, or
the selector which is sent to myself, to retrieve the Exception class / Signal.
Usage example(s):
Number
raise:#domainErrorSignal
receiver:1.0
selector:#foo
errorString:'foo bar test'
|
-
raise: anErrorClass receiver: someNumber selector: sel arguments: argArray errorString: text defaultValue: defaultValueIfProceeded
-
migrating away from ST-80 compatible signal raising.
This provides the default value, if the exception is proceeded
(i.e. for imaginary results).
Usage example(s):
Number
raise:DomainError
receiver:1.0
selector:#foo
arguments:#()
errorString:'foo bar test'
defaultValue:99.99
|
exception handling
-
trapDomainError: aBlock
-
evaluate aBlock;
if any DomainError occurs inside, proceed with either the operation's
specified default value or with a NaN.
This allows for regular (failing) code to transparently convert to
some fallBack and behave similar to other systems which do that.
Usage example(s):
this raises an error:
0 ln
this returns NaN:
Number trapDomainError: [0 ln]
|
-
trapImaginary: aBlock
-
evaluate aBlock;
if any ImaginaryResult occurs inside, which would return an imaginary result,
(eg. square root of negative number),
convert the result to a complex number and proceed.
This allows for regular (failing) code to transparently convert to complex.
Usage example(s):
this raises an error:
-2 sqrt
this returns an imaginary result:
Complex trapImaginary: [-2 sqrt]
of course, this one as well:
-2 asComplex sqrt
|
-
trapInfinity: aBlock
-
evaluate aBlock;
if any DomainError occurs inside, which would return an infinite result,
(eg. ln of zero),
convert the result to infinity and proceed.
This allows for regular (failing) code to transparently convert to infinity and behave
similar to other systems which do that.
Usage example(s):
this raises an error:
0 ln
this returns an imaginary result:
Number trapInfinity: [0 ln]
|
-
trapOverflow: aBlock
-
evaluate aBlock;
if an Overflow occurs inside, return INF and proceed.
Usage example(s):
this raises an error:
1000 factorial asShortFloat
this returns an imaginary result:
Number trapOverflow: [ 1000 factorial asShortFloat]
|
-
trapUnderflow: aBlock
-
evaluate aBlock;
if an Underflow occurs inside, return zero and proceed.
Usage example(s):
this raises an error:
1.0 / (1000 factorial)
this returns an imaginary result:
Number trapUnderflow: 1.0 / (1000 factorial)]
|
queries
-
isAbstract
-
Return if this class is an abstract class.
True is returned for ArithmeticValue here; false for subclasses.
Abstract subclasses must redefine this again.
Compatibility-Squeak
-
absSquared
( an extension from the stx:libcompat package )
-
who needs this???
-
rounded: n
( an extension from the stx:libcompat package )
-
marked as obsolete by exept MBP at 17-09-2021
** This is an obsolete interface - do not use it (it may vanish in future versions) **
JavaScript support
-
js_add: aNumberOrString
( an extension from the stx:libjavascript package )
-
For JavaScript only:
Generated for +-operator in javascript.
-
js_addFromNumber: aNumber
( an extension from the stx:libjavascript package )
-
For JavaScript only:
Generated for +-operator in javascript.
-
js_addFromTime: aTime
( an extension from the stx:libjavascript package )
-
For JavaScript only:
Generated for +-operator in javascript.
arithmetic
-
% aNumber
-
modulo. Remainder defined in terms of //.
Answer a Number with the same sign as aNumber.
Usage example(s):
Usage example(s):
Usage example(s):
-
* something
-
return the product of the receiver and the argument.
** This method must be redefined in concrete classes (subclassResponsibility) **
-
*% percent
-
multiply the receiver by the given percentage;
i.e. return self * (percent / 100)
Usage example(s):
200 *% 3 -> 6
200.0 *% 3 -> 6.0
|
-
+ something
-
return the sum of the receiver and the argument
** This method must be redefined in concrete classes (subclassResponsibility) **
-
+% percent
-
add the given percentage of the receiver to the receiver;
i.e. return self + (self * (percent / 100))
Usage example(s):
-
- something
-
return the difference of the receiver and the argument
** This method must be redefined in concrete classes (subclassResponsibility) **
-
-% percent
-
subtract the given percentage of the receiver to the receiver;
i.e. return self - (self * (percent / 100))
Usage example(s):
-
/ something
-
return the quotient of the receiver and the argument
** This method must be redefined in concrete classes (subclassResponsibility) **
-
// aNumber
-
return the integer quotient of dividing the receiver by aNumber with
truncation towards negative infinity.
Please be aware of the effect of truncation on negative receivers,
and understand the difference between '//' vs. 'quo:'
and the corresponding '\\' vs. 'rem:'
** This method must be redefined in concrete classes (subclassResponsibility) **
-
\\ something
-
return the receiver modulo something.
The remainder has the same sign as the argument, something.
The following is always true:
(receiver // something) * something + (receiver \\ something) = receiver
Please be aware of the effect of truncation on negative receivers,
and understand the difference between '//' vs. 'quo:'
and the corresponding '\\' vs. 'rem:'.
Usage example(s):
1.5 \\ 1 => 0.5
1.5 \\ 2 => 1.5
-1.5 \\ 1 => 0.5
-1.5 \\ 2 => 0.5
-1.5 \\ -1 => -0.5
-1.5 \\ -2 => -1.5
0.9 \\ 0.4 => 0.1
0.9 \\ -0.4 => -0.3
-0.9 \\ 0.4 => 0.3
-0.9 \\ -0.4 => -0.1
|
-
abs
-
return the absolute value of the receiver
-
copySignTo: aNumber
-
Return aNumber with its original magnitude
and same sign as the receiver
Usage example(s):
-15 copySignTo:1234 -> -1234
-15 copySignTo:-1234 -> -1234
15 copySignTo:1234 -> 1234
15 copySignTo:-1234 -> 1234
1.0 copySignTo:0.0 -> 0.0
-1.0 copySignTo:0.0 -> -0.0
1 copySignTo:(1/3) -> (1/3)
-1 copySignTo:(1/3) -> (-1/3)
|
-
dist: arg
-
return the distance between the arg and the receiver.
Usage example(s):
(1%1) dist:(0%0)
(1@1) dist:(0@0)
(1) dist:(0)
|
-
modulusOf: aNumber
-
return aNumber modulo the receiver.
The remainder has the same sign as something.
Defined for protocol compatibility with ModuloNumber.
-
negated
-
return the receiver negated
-
percent
-
1050.0 * 15 percent
-
percentOf: aValue
-
10 percentOf:1050.0 => 105.0
100 percentOf:1050.0 => 1050.0
200 percentOf:1050.0 => 2100.0
-
permille
-
1050.0 * 15 permille
-
permilleOf: aValue
-
10 permilleOf:1050.0 => 10.5
100 permilleOf:1050.0 => 105.0
200 permilleOf:1050.0 => 210.0
1000 permilleOf:1050.0 => 1050.0
-
quo: something
-
Return the integer quotient of dividing the receiver by the argument
with truncation towards zero.
Please be aware of the effect of truncation on negative receivers,
and understand the difference between '//' vs. 'quo:'
and the corresponding '\\' vs. 'rem:'.
The following is always true:
(receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
For positive results, this is the same as #//,
for negative results, the remainder is ignored.
I.e.: '9 // 4 = 2' and '-9 // 4 = -3'
in contrast: '9 quo: 4 = 2' and '-9 quo: 4 = -2'
-
reciprocal
-
return the receiver's reciprocal
Usage example(s):
(10 + 4i) class unity -> (1+0i)
(10 + 4i) reciprocal -> ((5/58)-(1/29)i)
(4/3) reciprocal -> (3/4)
3 reciprocal -> (1/3)
3.0 reciprocal -> 0.333333333333333
3.0 asLongFloat reciprocal -> 0.3333333333333333333
3.0 asShortFloat reciprocal -> 0.3333333
|
-
rem: something
-
Return the integer remainder of dividing the receiver by the argument
with truncation towards zero.
The remainder has the same sign as the receiver.
The following is always true:
(receiver quo: something) * something + (receiver rem: something) = receiver
Please be aware of the effect of truncation on negative receivers,
and understand the difference between '//' vs. 'quo:'
and the corresponding '\\' vs. 'rem:'.
-
uncheckedDivide: aNumber
-
return the quotient of the receiver and the argument, aNumber.
Do not check for divide by zero (return NaN or Infinity).
This operation is provided for emulators of other languages/semantics,
where no exception is raised for these results (i.e. Java).
It is only defined if the argument's type is the same as the receiver's.
arithmetic destructive
-
*= aNumber
-
Return the product of self multiplied by aNumber.
The receiver MAY, but NEED NOT be changed to contain the product.
So this method must be used as in: 'a := a *= 5'.
This method can be redefined in special datatypes to do optimisations
(especially vectors and matrices)
-
+= aNumber
-
Return the sum of self and aNumber.
The receiver MAY, but NEED NOT be changed to contain the sum.
So this method must be used as in: 'a := a += 5'.
This method can be redefined in special datatypes to do optimisations
(especially vectors and matrices)
-
-= aNumber
-
Return the difference of self and aNumber.
The receiver MAY, but NEED NOT be changed to contain the difference.
So this method must be used as in: 'a := a -= 5'.
This method can be redefined in special datatypes to do optimisations
(especially vectors and matrices)
-
/= aNumber
-
Return the quotient of self and aNumber.
The receiver MAY, but NEED NOT be changed to contain the quotient.
So this method must be used as in: 'a := a /= 5'.
This method can be redefined in special datatypes to do optimisations
(especially vectors and matrices)
-
div2
-
Return the quotient of self divided by 2.
The receiver MAY, but NEED NOT be changed to contain the result.
So this method must be used as in: 'a := a div2'.
This method can be redefined in special datatypes to do optimisations
(especially vectors and matrices)
-
mul2
-
Return the product of self multiplied by 2.
The receiver MAY, but NEED NOT be changed to contain the result.
So this method must be used as in: 'a := a mul2'.
This method can be redefined in special datatypes to do optimisations
(especially vectors and matrices)
coercing & converting
-
coerce: aNumber
-
convert the argument aNumber into an instance of the receiver's class and return it.
-
generality
-
return a number giving the receiver's generality.
That number is used to convert one of the arguments in a mixed expression.
The generality has to be defined in subclasses,
such that gen(a) > gen(b) iff, conversion of b into a's class
does not cut precision.
For example, Integer has 40, Float has 80, meaning that if we convert a Float to an Integer,
some precision may be lost.
The generality is used by ArithmeticValue>>retry:coercing:,
which converts the lower-precision number to the higher precision
number's class, when mixed-type arithmetic is performed.
-
retry: aSymbol coercing: aNumber
-
arithmetic represented by the binary operator, aSymbol,
could not be performed with the receiver and the argument, aNumber,
because of the differences in representation.
Coerce either the receiver or the argument, depending on which has higher
generality, and try again.
If the operation is compare for same value (=), return false if
the argument is not a Number.
If the generalities are the same, create an error message, since this
means that a subclass has not been fully implemented.
Usage example(s):
self error:'retry:coercing: oops - same generality; retry should not happen'
|
-
retry: aSymbol coercing: aNumber with: anArgument
-
arithmetic represented by the binary operator, aSymbol,
could not be performed with the receiver and the argument, aNumber,
because of the differences in representation.
Coerce either the receiver or the argument, depending on which has higher
generality, and try again.
If the operation is compare for same value (=), return false if
the argument is not a Number.
If the generalities are the same, create an error message, since this
means that a subclass has not been fully implemented.
Usage example(s):
self error:'retry:coercing: oops - same generality; retry should not happen'
|
-
zero
-
return a zero in my class and my precision
converting
-
as32BitIEEEFloatBytesMSB: msb
-
2 as32BitIEEEFloatBytesMSB:true
2.0 as32BitIEEEFloatBytesMSB:true
-
as64BitIEEEFloatBytesMSB: msb
-
2 as64BitIEEEFloatBytesMSB:true
2.0 as64BitIEEEFloatBytesMSB:true
-
asDouble
-
ST80 compatibility: return a double with receiver's value.
Attention: our floats are the identical to ST80's doubles
-
asFixedDecimal
-
return a fixedDecimal approximating the receiver's value
to 2 fractional digits
Usage example(s):
1.234 asFixedDecimal -> 1.23
1.234 asScaledDecimal -> 1.23
1.238 asFixedDecimal -> 1.24
1.238 asScaledDecimal -> 1.24
1.234 asFixedDecimal * 2 -> 2.46
1.234 asScaledDecimal * 2 -> 2.47
|
-
asFixedDecimal: scale
-
return a fixedDecimal approximating the receiver's value
to scale fractional digits
Usage example(s):
1.234 asFixedDecimal:4 -> 1.2340
1.234 asFixedDecimal:3 -> 1.234
1.234 asFixedDecimal:2 -> 1.23
1.234 asFixedDecimal:1 -> 1.2
1.234 asFixedDecimal:0 -> 1
123 asFixedDecimal:-1 -> 120
1234 asFixedDecimal:-1 -> 1230
|
-
asFixedPoint
-
marked as obsolete by exept MBP at 18-09-2021
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
asFixedPoint: scale
-
marked as obsolete by exept MBP at 18-09-2021
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
asFixedPointRoundedToScale
-
marked as obsolete by exept MBP at 18-09-2021
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
asFixedPointRoundedToScale: scale
-
marked as obsolete by exept MBP at 18-09-2021
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
asFloat
-
return a float with same value
** This method must be redefined in concrete classes (subclassResponsibility) **
-
asFloat128
-
return a quadruple precision float with same value.
-
asFloat16
-
return a shortFloat with same value.
Does NOT raise an error if the receiver exceeds the float range.
Usage example(s):
10 asFloat16 -> 10.0
10.0 asFloat16 -> 10.0
|
-
asFloat256
-
return a octuple precision float with same value.
-
asFloat32
-
return a shortFloat with same value.
Does NOT raise an error if the receiver exceeds the float range.
-
asFloat64
-
return a double precision float with same value.
-
asFloat80
-
return an extended precision float (80 bit) with same value.
-
asFloatD
-
return a double precision float with same value.
Added for ANSI compatibility
-
asFloatE
-
return a single precision float with same value.
Added for ANSI compatibility
-
asFloatQ
-
return an extended precision float with same value.
Notice that longFloats as returned here may or may not provide more
precision than a double - depending on the machine's CPU
(and usually do not provide quad the number of bits of a float)
Added for ANSI compatibility
-
asFloatQD
-
return a quad double precision float with same value.
-
asFraction
-
return a fraction with same value
** This method must be redefined in concrete classes (subclassResponsibility) **
-
asInteger
-
return an integer with same value - might truncate
-
asLargeFloat
-
return a largeFloat with same value
-
asLimitedPrecisionReal
-
return a float of any precision with same value
-
asLongFloat
-
return a longFloat with same value
-
asOctaFloat
( an extension from the stx:libbasic2 package )
-
return an octaFloat with same value
-
asQDouble
( an extension from the stx:libbasic2 package )
-
return a QDouble with same value
Usage example(s):
123 asQDouble
(Fraction basicNew setNumerator:246 denominator:2) asQDouble
123 asLongFloat asQDouble
123 asLargeFloat asQDouble
|
-
asQuadFloat
( an extension from the stx:libbasic2 package )
-
return a quadFloat with same value
-
asScaledDecimal
-
return the receiver as asScaledDecimal number.
Here, a default scale (2) is set.
Q: what should the scale be here ?
Usage example(s):
0.3 asScaledDecimal => 0.30
0.5 asScaledDecimal => 0.50
(1/5) asFloat asScaledDecimal => 0.20
(1/3) asFloat asScaledDecimal => 0.33
(2/3) asFloat asScaledDecimal => 0.67
(2/3) asFloat asScaledDecimal:5 => 0.66667
(1/8) asFloat asScaledDecimal => 0.13
(1/10) asScaledDecimal => 0.10
3.14159 asScaledDecimal => 3.14
3.14159 asScaledDecimal:3 => 3.142
3.14159 asScaledDecimal:4 => 3.1416
3.14159 asScaledDecimal:5 => 3.14159
3.14159 asScaledDecimal:6 => 3.141590
0.0000001 asScaledDecimal => 0.00
0.0000001 asScaledDecimal => 0.00
|
-
asScaledDecimal: scale
-
return a scaledDecimal approximating the receiver's value
Usage example(s):
^ (self roundTo:(1.0 / 10 raisedTo:scale+1)) asFraction asScaledDecimal:scale
|
Usage example(s):
1.234 asScaledDecimal:4 => 1.2340
1.234 asScaledDecimal:3 => 1.234
1.234 asScaledDecimal:2 => 1.23
1.234 asScaledDecimal:1 => 1.2
1.234 asScaledDecimal:0 => 1
1.2345 asScaledDecimal:4 => 1.2345
1.2346 asScaledDecimal:3 => 1.235
1.2345 asScaledDecimal:3 => 1.235
1.8 asScaledDecimal:0 => 2
(2/3) asFloat asScaledDecimal => 0.67
(2/3) asFloat asScaledDecimal:5 => 0.66667
(2/3) asFloat asScaledDecimal:8 => 0.66666667
|
-
asScaledDecimalRoundedToScale
-
return the receiver as scaled decimal number,
rounded to its default scale (2).
Usage example(s):
0.3 asScaledDecimal
0.5 asScaledDecimal
(2/3) asFloat asScaledDecimal
(1/8) asFloat asScaledDecimal
3.14159 asScaledDecimal
0.3 asScaledDecimalRoundedToScale
0.5 asScaledDecimalRoundedToScale
(2/3) asFloat asScaledDecimalRoundedToScale
(1/8) asFloat asScaledDecimalRoundedToScale
3.14159 asScaledDecimalRoundedToScale
|
-
asScaledDecimalRoundedToScale: scale
-
return the receiver as scaled decimal number with the given
number of post-decimal-digits, rounded to the given scale
Usage example(s):
3.14159 asScaledDecimalRoundedToScale:1
3.14159 asScaledDecimalRoundedToScale:2
3.14159 asScaledDecimalRoundedToScale:3 -> 3.142
3.14159 asScaledDecimalRoundedToScale:4 -> 3.1416
3.14159 asScaledDecimalTruncatedToScale:3 -> 3.141
3.14159 asScaledDecimalTruncatedToScale:4 -> 3.1415
|
-
asScaledDecimalTruncatedToScale
-
return the receiver as scaled decimal number,
truncated to its default scale (2).
Usage example(s):
0.3 asScaledDecimal
0.5 asScaledDecimal
(2/3) asFloat asScaledDecimal
(1/8) asFloat asScaledDecimal
3.14159 asScaledDecimal
0.3 asScaledDecimalRoundedToScale
0.5 asScaledDecimalRoundedToScale
(2/3) asFloat asScaledDecimalRoundedToScale -> 0.67
(2/3) asFloat asScaledDecimalTruncatedToScale -> 0.66
(1/8) asFloat asScaledDecimalRoundedToScale -> 0.13
(1/8) asFloat asScaledDecimalTruncatedToScale -> 0.12
3.14159 asScaledDecimalRoundedToScale
|
-
asScaledDecimalTruncatedToScale: scale
-
return the receiver as scaled decimal number with the given
number of post-decimal-digits, truncated to the given scale
Usage example(s):
3.14159 asScaledDecimalTruncatedToScale:1 -> 3.1
3.14159 asScaledDecimalTruncatedToScale:2 -> 3.14
3.14159 asScaledDecimalTruncatedToScale:3 -> 3.141
3.14159 asScaledDecimalTruncatedToScale:4 -> 3.1415
3.14159 asScaledDecimalRoundedToScale:3 -> 3.142
3.14159 asScaledDecimalRoundedToScale:4 -> 3.1416
|
-
asShortFloat
-
return a shortFloat with same value.
Does NOT raise an error if the receiver exceeds the float range.
-
degreesToRadians
-
interpreting the receiver as degrees, return the radians
-
radiansToDegrees
-
interpreting the receiver as radians, return the degrees
double dispatching
-
bitAndFromInteger: anInteger
-
anInteger does not know how to do bitAnd: with the receiver -
retry the operation by coercing to Integer
-
bitOrFromInteger: anInteger
-
anInteger does not know how to do bitOr: with the receiver -
retry the operation by coercing to Integer
-
bitXorFromInteger: anInteger
-
anInteger does not know how to do bitXor: with the receiver -
retry the operation by coercing to Integer
-
differenceFromComplex: aComplex
-
aComplex does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromFixedDecimal: aFixedDecimal
( an extension from the stx:libbasic2 package )
-
aFixedDecimal does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromFloat: aFloat
-
aFloat does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromFraction: aFraction
-
aFraction does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromIEEEFloat: anIEEEFloat
( an extension from the stx:libbasic2 package )
-
anIEEEFloat does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromInteger: anInteger
-
anInteger does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromLargeFloat: aLargeFloat
-
aLargeFloat does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromLongFloat: aLongFloat
-
aLongFloat does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromNumber: aNumber
-
aNumber does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromOctaFloat: anOctaFloat
( an extension from the stx:libbasic2 package )
-
anOctaFloat does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromQDouble: aQDouble
( an extension from the stx:libbasic2 package )
-
aQDouble does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromQuadFloat: aQuadFloat
( an extension from the stx:libbasic2 package )
-
aQuadFloat does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromScaledDecimal: aScaledDecimal
-
aScaledDecimal does not know how to subtract the receiver -
Return true if aScaledDecimal - self.
retry the operation by coercing to higher generality
-
differenceFromShortFloat: aShortFloat
-
aShortFloat does not know how to subtract the receiver -
retry the operation by coercing to higher generality
-
differenceFromTimeDuration: aTimeDuration
-
aTimeDuration does not know how to subtract the receiver;
but I know, interpreting the receiver as seconds
-
equalFromComplex: aComplex
-
aComplex does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromFixedDecimal: aFixedDecimal
( an extension from the stx:libbasic2 package )
-
aFixedDecimal does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromFloat: aFloat
-
aFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromFraction: aFraction
-
aFraction does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromIEEEFloat: anIEEEFloat
( an extension from the stx:libbasic2 package )
-
anIEEEFloat does not know how to compare against by the receiver -
retry the operation by coercing to higher generality
-
equalFromInteger: anInteger
-
anInteger does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromLargeFloat: aLargeFloat
-
aLargeFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromLongFloat: aLongFloat
-
aLongFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromNumber: aNumber
-
aNumber does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromOctaFloat: anOctaFloat
( an extension from the stx:libbasic2 package )
-
anOctaFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromQDouble: aQDouble
( an extension from the stx:libbasic2 package )
-
aQDouble does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromQuadFloat: aQuadFloat
( an extension from the stx:libbasic2 package )
-
aQuadFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromScaledDecimal: aScaledDecimal
-
aScaledDecimal does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
equalFromShortFloat: aShortFloat
-
aShortFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
integerQuotientFromInteger: anInteger
-
anInteger does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
isAlmostEqualToFromFloat: aFloat nEpsilon: nE
-
aFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
isAlmostEqualToFromLargeFloat: aLargeFloat nEpsilon: nE
-
aLargeFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
isAlmostEqualToFromLongFloat: aLongFloat nEpsilon: nE
-
aLongFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
isAlmostEqualToFromOctaFloat: anOctaFloat nEpsilon: nE
( an extension from the stx:libbasic2 package )
-
anOctaFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
isAlmostEqualToFromQuadFloat: aQuadFloat nEpsilon: nE
( an extension from the stx:libbasic2 package )
-
aQuadFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
isAlmostEqualToFromShortFloat: aShortFloat nEpsilon: nE
-
aShortFloat does not know how to compare to the receiver -
retry the operation by coercing to higher generality
-
lessFromFixedDecimal: aFixedDecimal
( an extension from the stx:libbasic2 package )
-
aFixedDecimal does not know how to compare to the receiver -
Return true if aFixedDecimal < self.
retry the operation by coercing to higher generality
-
lessFromFloat: aFloat
-
aFloat does not know how to compare to the receiver -
Return true if aFloat < self.
retry the operation by coercing to higher generality
-
lessFromFraction: aFraction
-
aFraction does not know how to compare to the receiver -
Return true if aFraction < self.
retry the operation by coercing to higher generality
-
lessFromIEEEFloat: anIEEEFloat
( an extension from the stx:libbasic2 package )
-
anIEEEFloat does not know how to compare against by the receiver -
retry the operation by coercing to higher generality
-
lessFromInteger: anInteger
-
anInteger does not know how to compare to the receiver -
Return true if anInteger < self.
retry the operation by coercing to higher generality
-
lessFromLargeFloat: aLargeFloat
-
aLargeFloat does not know how to compare to the receiver -
Return true if aLargeFloat < self.
retry the operation by coercing to higher generality
-
lessFromLongFloat: aLongFloat
-
aLongFloat does not know how to compare to the receiver -
Return true if aLongFloat < self.
retry the operation by coercing to higher generality
-
lessFromNumber: aNumber
-
aNumber does not know how to compare to the receiver -
Return true if aNumber < self.
retry the operation by coercing to higher generality
-
lessFromOctaFloat: anOctaFloat
( an extension from the stx:libbasic2 package )
-
anOctaFloat does not know how to compare to the receiver -
Return true if anOctaFloat < self.
retry the operation by coercing to higher generality
-
lessFromQDouble: aQDouble
( an extension from the stx:libbasic2 package )
-
aQDouble does not know how to compare to the receiver -
Return true if aQDouble < self.
retry the operation by coercing to higher generality
-
lessFromQuadFloat: aQuadFloat
( an extension from the stx:libbasic2 package )
-
aQuadFloat does not know how to compare to the receiver -
Return true if aQuadFloat < self.
retry the operation by coercing to higher generality
-
lessFromRaisedNumber: aNumber
( an extension from the stx:libbasic2 package )
-
aNumber does not know how to compare to the receiver -
Return true if aNumber < self.
retry the operation by coercing to higher generality
-
lessFromScaledDecimal: aScaledDecimal
-
aScaledDecimal does not know how to compare to the receiver -
Return true if aScaledDecimal < self.
retry the operation by coercing to higher generality
-
lessFromShortFloat: aShortFloat
-
aShortFloat does not know how to compare to the receiver -
Return true if aShortFloat < self.
retry the operation by coercing to higher generality
-
moduloFromInteger: anInteger
-
anInteger does not know how to compute the modulo from the receiver -
retry the operation by coercing to higher generality
-
productFromComplex: aComplex
-
aComplex does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromFixedDecimal: aFixedDecimal
( an extension from the stx:libbasic2 package )
-
aFixedDecimal does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromFloat: aFloat
-
aFloat does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromFraction: aFraction
-
aFraction does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromIEEEFloat: anIEEEFloat
( an extension from the stx:libbasic2 package )
-
anIEEEFloat does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromInteger: anInteger
-
anInteger does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromLargeFloat: aLargeFloat
-
aLargeFloat does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromLongFloat: aLongFloat
-
aLongFloat does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromNumber: aNumber
-
aNumber does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromOctaFloat: anOctaFloat
( an extension from the stx:libbasic2 package )
-
anOctaFloat does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromQDouble: aQDouble
( an extension from the stx:libbasic2 package )
-
aQDouble does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromQuadFloat: aQuadFloat
( an extension from the stx:libbasic2 package )
-
aQuadFloat does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromScaledDecimal: aScaledDecimal
-
aScaledDecimal does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromShortFloat: aShortFloat
-
aShortFloat does not know how to multiply the receiver -
retry the operation by coercing to higher generality
-
productFromTimeDuration: aTimeDuration
-
return aTimeDuration * self
-
quotientFromComplex: aComplex
-
aComplex does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromFixedDecimal: aFixedDecimal
( an extension from the stx:libbasic2 package )
-
aFixedDecimal does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromFloat: aFloat
-
aFloat does not know how to divide by the receiver.
Retry the operation by coercing to higher generality.
Return aFloat / self
-
quotientFromFraction: aFraction
-
aFraction does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromIEEEFloat: anIEEEFloat
( an extension from the stx:libbasic2 package )
-
anIEEEFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromInteger: anInteger
-
anInteger does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromLargeFloat: aLargeFloat
-
aLargeFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromLongFloat: aLongFloat
-
aLongFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromNumber: aNumber
-
aNumber does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromOctaFloat: anOctaFloat
( an extension from the stx:libbasic2 package )
-
anOctaFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromQDouble: aQDouble
( an extension from the stx:libbasic2 package )
-
aQDouble does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromQuadFloat: aQuadFloat
( an extension from the stx:libbasic2 package )
-
aQuadFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromScaledDecimal: aScaledDecimal
-
aScaledDecimal does not know how to divide by the receiver -
Return true if aScaledDecimal / self.
retry the operation by coercing to higher generality
-
quotientFromShortFloat: aShortFloat
-
aShortFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromTimeDuration: aTimeDuration
-
return aTimeDuration / self
-
raisedFromFloat: aFloat
-
aFloat does not know how to be raised to the receiver
-
raisedFromNumber: someNumber
-
aNumber does not know how to be raised to the receiver
(i.e. how to compute
aNumber ** self
)
-
remainderFromFixedDecimal: aFixedDecimal
( an extension from the stx:libbasic2 package )
-
aFixedDecimal does not know how to compute the remainder with the receiver -
retry the operation by coercing to higher generality
-
remainderFromFloat: aFloat
-
aFloat does not know how to compute the remainder with the receiver -
retry the operation by coercing to higher generality
-
remainderFromIEEEFloat: anIEEEFloat
( an extension from the stx:libbasic2 package )
-
anIEEEFloat does not know how to compute the remainder with the receiver -
retry the operation by coercing to higher generality
-
remainderFromLargeFloat: aLargeFloat
-
aLargeFloat does not know how to compute the remainder with the receiver -
retry the operation by coercing to higher generality
-
remainderFromLongFloat: aLongFloat
-
aLongFloat does not know how to compute the remainder with the receiver -
retry the operation by coercing to higher generality
-
remainderFromNumber: aNumber
-
aNumber does not know how to compute the remainder with the receiver -
retry the operation by coercing to higher generality
-
remainderFromOctaFloat: anOctaFloat
( an extension from the stx:libbasic2 package )
-
anOctaFloat does not know how to compute the remainder with the receiver -
retry the operation by coercing to higher generality
-
remainderFromQDouble: aQDouble
( an extension from the stx:libbasic2 package )
-
aQDouble does not know how to compute the remainder with the receiver -
retry the operation by coercing to higher generality
-
remainderFromQuadFloat: aQuadFloat
( an extension from the stx:libbasic2 package )
-
aQuadFloat does not know how to compute the remainder with the receiver -
retry the operation by coercing to higher generality
-
remainderFromShortFloat: aShortFloat
-
aShortFloat does not know how to compute the remainder with the receiver -
retry the operation by coercing to higher generality
-
sumFromComplex: aComplex
-
aComplex does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromFixedDecimal: aFixedDecimal
( an extension from the stx:libbasic2 package )
-
aFixedDecimal does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromFloat: aFloat
-
aFloat does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromFraction: aFraction
-
aFraction does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromIEEEFloat: anIEEEFloat
( an extension from the stx:libbasic2 package )
-
anIEEEFloat does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromInteger: anInteger
-
anInteger does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromLargeFloat: aLargeFloat
-
aLargeFloat does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromLongFloat: aLongFloat
-
aLongFloat does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromNumber: aNumber
-
aNumber does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromOctaFloat: anOctaFloat
( an extension from the stx:libbasic2 package )
-
anOctaFloat does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromQDouble: aQDouble
( an extension from the stx:libbasic2 package )
-
aQDouble does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromQuadFloat: aQuadFloat
( an extension from the stx:libbasic2 package )
-
aQuadFloat does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromScaledDecimal: aScaledDecimal
-
aScaledDecimal does not know how to add the receiver -
retry the operation by coercing to higher generality
-
sumFromShortFloat: aShortFloat
-
aShortFloat does not know how to add the receiver -
retry the operation by coercing to higher generality
mathematical functions
-
** aNumber
-
Answer the receiver raised to the power of the argument, aNumber.
-
cubed
-
return receiver ^ 3
-
raisedTo: aNumber
-
return the receiver raised to aNumber (i.e. self ^ aNumber)
Usage example(s):
2 raisedTo:16
2.0 raisedTo:16
3 raisedTo:4
10@10 raisedTo:4
10@10 raisedTo:4.0
|
-
raisedToInteger: exp
-
return the receiver raised to exp.
Warning: if the receiver is a float/double,
INF may be returned on overflow.
This may be changed silently to raise an error in future versions.
Usage example(s):
0x10000000000000000 raisedToInteger:6
(2 raisedToInteger:216) -> 105312291668557186697918027683670432318895095400549111254310977536
(2.0 raisedToInteger:216) -> 1.05312291668557E+65
(2.0 asLongFloat) raisedToInteger:216 -> 1.053122916685571867E+65
(2.0 asShortFloat) raisedToInteger:216 -> inf
(2.0 asQDouble) raisedToInteger:216
(2 raisedTo:216)
-> 105312291668557186697918027683670432318895095400549111254310977536
(2.0 raisedToInteger:216) asInteger - (2 raisedToInteger:216)
(2.0 raisedToInteger:400) asInteger - (2 raisedToInteger:400)
(2.0 raisedToInteger:500) asInteger - (2 raisedToInteger:500)
(2.0 raisedToInteger:1000) asInteger - (2 raisedToInteger:1000)
(2.0 raisedToInteger:2000)
(2.0 asLongFloat raisedToInteger:2000) 1.148130695274254524E+602
(2.0 asLargeFloat raisedToInteger:2000)
- (2.0 asLongFloat raisedToInteger:2000)
(2 raisedToInteger:216) asFloat
(2 raisedTo:216) asFloat -> 1.05312E+65
(2 raisedToInteger:500)
(2 raisedTo:500)
-> 3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376
(2 raisedTo:-500)
-> (1/3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376)
2 raisedToInteger:10 -> 1024
-2 raisedToInteger:10 -> 1024
-2 raisedToInteger:9 -> -512
10 raisedToInteger:-10 -> (1/10000000000)
2 raisedToInteger:0 -> 1
2 raisedToInteger:-1 -> (1/2)
(10.0 asShortFloat raisedToInteger:1) digitBytes #[0 0 32 65]
(10.0 asShortFloat asIEEEFloat raisedToInteger:1) digitBytes #[0 0 32 65]
(10.0 asShortFloat raisedToInteger:2) digitBytes #[0 0 200 66]
(10.0 asShortFloat asIEEEFloat raisedToInteger:2) digitBytes #[0 0 200 66]
(10.0 asShortFloat raisedToInteger:-2) digitBytes #[10 215 35 60]
(10.0 asShortFloat asIEEEFloat raisedToInteger:-2) digitBytes #[10 215 35 60]
(10.0 asShortFloat raisedToInteger:-6) digitBytes #[189 55 134 53]
(10.0 asShortFloat asIEEEFloat raisedToInteger:-6) digitBytes #[189 55 134 53
(10.0 asShortFloat * 10.0 asShortFloat) digitBytes #[0 0 200 66]
(10.0 asShortFloat asIEEEFloat * 10.0 asShortFloat asIEEEFloat) digitBytes #[0 0 200 66]
0 raisedToInteger:-1 -> error
Number trapInfinity:[0 raisedToInteger:-1] -> INF
Time millisecondsToRun:[
10000 timesRepeat:[
(2 raisedToInteger:500)
]
]
Time millisecondsToRun:[
|bigNum|
bigNum := 2 raisedToInteger:500.
10 timesRepeat:[
(bigNum raisedToInteger:500)
]
]
|
-
squared
-
return receiver * receiver
testing
-
denominator
-
return the denominator of the receiver
-
even
-
return true if the receiver is divisible by 2.
This is only defined for whole-numbers (integers).
Usage example(s):
^ self truncated asInteger even
|
Usage example(s):
2.4 even -> error
Number trapDomainError:[2.4 even] -> false
2.0 even -> true
1.0 even -> false
|
-
isComplex
-
Answer whether the receiver has an imaginary part
(i.e. if it is a complex number). Always false here.
-
isFinite
-
return true, if the receiver is finite (not NaN and not +/-INF)
i.e. it can be represented as a rational number.
MUST be redefined in meta numbers and numbers which have a
representation for infinities (eg. IEEE floats)
-
isFixedDecimal
( an extension from the stx:libbasic2 package )
-
-
isFloat128
-
Answer whether the receiver is a 128bit quadruple precision float.
Always false here.
-
isFloat256
-
Answer whether the receiver is a 128bit octuple precision float.
Always false here.
-
isFloat32
-
Answer whether the receiver is a 32bit single precision float.
Always false here.
-
isFloat64
-
Answer whether the receiver is a 64bit double precision float.
Always false here.
-
isFloat80
-
Answer whether the receiver is a 80bit extended precision float.
Always false here.
-
isInfinite
-
return true, if the receiver is an infinite number (+Inf or -Inf).
MUST be redefined in meta numbers and numbers which have a
representation for infinities (eg. IEEE floats)
-
isNaN
-
return true, if the receiver is an invalid number (NaN - not a number).
-
isNegativeInfinity
-
-
isNegativeZero
-
return false - must be redefined by subclasses which can represent a negative zero
(i.e. limitedPrecisionReal classes)
-
isPositiveInfinity
-
-
isReal
-
return true, if the receiver is some kind of real number (as opposed to a complex);
false is returned here - the method is only redefined in Number (and Complex).
-
isZero
-
return true if I represent a zero value (neutral addition element).
MUST be redefined by subclasses which can represent multiple zeros
(i.e. a negative zero, as in IEEE floats)
-
negative
-
return true if the receiver is less than zero.
-
numerator
-
return the numerator of the receiver.
-
odd
-
return true if the receiver is not divisible by 2
-
positive
-
return true, if the receiver is greater or equal to zero (not negative)
-
respondsToArithmetic
-
return true, if the receiver responds to arithmetic messages.
This should return true for any object which represents a scalar,
matrix, point, physical value or similar object
which can add, subtract, etc.
-
sign
-
return the sign of the receiver (-1, 0 or 1)
-
signBit
-
return my sign bit (0 for positive, 1 for negative).
For compatibility with IEEE floats.
-
strictlyPositive
-
return true, if the receiver is greater than zero
truncation & rounding
-
ceiling
-
return the integer nearest the receiver towards positive infinity.
Usage example(s):
5 ceiling -> 5
5.0 ceiling -> 5
5.1 ceiling -> 6
5.9 ceiling -> 6
5.0000001 ceiling -> 6
-5 ceiling -> -5
-5.0 ceiling -> -5
-5.1 ceiling -> -5
-5.9 ceiling -> -5
-5.0000001 ceiling -> -5
-4.9 ceiling -> -4
-4.9999999 ceiling -> -4
|
-
floor
-
return the receiver truncated towards negative infinity
-
roundTo: aNumber
-
return the receiver rounded to the nearest multiple of aNumber
Usage example(s):
0 roundTo:4 -> 0
1 roundTo:4 -> 0
2 roundTo:4 -> 4
3 roundTo:4 -> 4
4 roundTo:4
5 roundTo:4 -> 4
6 roundTo:4 -> 8
7 roundTo:4
1.16 roundTo:0.1 -> 1.2
1.151 roundTo:0.1 -> 1.2
1.15 roundTo:0.1 -> 1.1 -- because 1.15 is not an exact float (actually a bit less)
1.149 roundTo:0.1 -> 1.1
1.14 roundTo:0.1 -> 1.1
7.99 roundTo:0.1 -> 8.0
7.15 roundTo:0.1 -> 7.2
7.149 roundTo:0.1 -> 7.1
7.123 roundTo:0.1
7.523 roundTo:0.1
7.583 roundTo:0.1
7.623 roundTo:0.1
7.623 roundTo:0.01 -> 7.62
7.624 roundTo:0.01 -> 7.62
7.625 roundTo:0.01 -> 7.63
7.628 roundTo:0.01 -> 7.63
7.628s3 roundTo:0.1 -> 7.60
7.628s3 roundTo:0.01 -> 7.63
7.628s3 roundTo:1 -> 8.0
|
-
roundToNumberOfDigits: precision
-
round to precision number of valid digits.
CAVEAT: somewhat clumsy naming; see comment in roundToPrecision
Usage example(s):
1.2345 roundToNumberOfDigits:2 -> 1.2
12.345 roundToNumberOfDigits:2 -> 12.0
123.45 roundToNumberOfDigits:2 -> 120.0
1234.5 roundToNumberOfDigits:2 -> 1200.0
3.14159 roundToNumberOfDigits:1 -> 3.0
3.14159 roundToNumberOfDigits:2 -> 3.1
3.14159 roundToNumberOfDigits:3 -> 3.14
3.14159 roundToNumberOfDigits:4 -> 3.142
3.14159 roundToNumberOfDigits:5 -> 3.1416
3.14159 roundToNumberOfDigits:6 -> 3.14159
3.1459 roundToNumberOfDigits:2 -> 3.1
314159 roundToNumberOfDigits:2 -> 310000
314159 roundToNumberOfDigits:3 -> 314000
314159 roundToNumberOfDigits:4 -> 314200
314159 roundToNumberOfDigits:5 -> 314160
314159 roundToNumberOfDigits:6 -> 314159
314159 roundToNumberOfDigits:7 -> 314159
31459 roundToNumberOfDigits:2 -> 31000
314159 asFloat roundToNumberOfDigits:2 -> 310000.0
314159 asFloat roundToNumberOfDigits:4 -> 314200.0
314159 asFloat roundToNumberOfDigits:5 -> 314160.0
314159 asFloat roundToNumberOfDigits:6 -> 314159.0
314159 asFloat roundToNumberOfDigits:7 -> 314159.0
|
-
roundToPrecision: scalePrecision
-
round to scalePrecision number of fractional decimal digits.
If the argument is negative, the receiver is rounded to
multiples of a power of 10 (i.e. with -1, to multiples of 10).
CAVEAT: wrong naming; should be called roundToNumberOfFractionalDigits
or similar. Because precision would be the overall number of digits. (sigh)
Usage example(s):
1.2345 roundToPrecision:2 -> 1.23
12.345 roundToPrecision:2 -> 12.35
123.45 roundToPrecision:2 -> 123.45
1234.5 roundToPrecision:2 -> 1234.5
3.14159 roundToPrecision:0 -> 3
3.54159 roundToPrecision:0 -> 4
3.14159 roundToPrecision:1 -> 3.1
3.14159 roundToPrecision:2 -> 3.14
3.14159 roundToPrecision:3 -> 3.142
3.14159 roundToPrecision:4 -> 3.1416
3.14159 roundToPrecision:5 -> 3.14159
3.14159 roundToPrecision:6 -> 3.14159
3.14159265358979 roundToPrecision:4 => 3.1416
3.14159265358979 roundToPrecision:5 => 3.14159
3.14159265358979 roundToPrecision:6 => 3.141593
3.14159265358979 roundToNumberOfDigits:6 => 3.14159
3.14159265358979 roundToNumberOfDigits:5 => 3.1416
3.14159265358979 roundToNumberOfDigits:4 => 3.142
31.4159265358979 roundToNumberOfDigits:4 => 31.42
3.1459 roundToPrecision:2 -> 3.15
314159 roundToPrecision:2 -> 314159
31459 roundToPrecision:2 -> 31459
31459 roundToPrecision:-1 -> 31460
31459 roundToPrecision:-2 -> 31500
31459 roundToPrecision:-3 -> 31000
31459 roundToPrecision:-4 -> 30000
35459 roundToPrecision:-4 -> 40000
31459 roundToPrecision:-5 -> 0
51459 roundToPrecision:-5 -> 100000
61459 roundToPrecision:-5 -> 100000
|
-
roundUpTo: aNumber
-
return the receiver rounded up to the next multiple of aNumber
Usage example(s):
0 roundUpTo:4 -> 0
1 roundUpTo:4 -> 4
2 roundUpTo:4 -> 4
3 roundUpTo:4 -> 4
4 roundUpTo:4 -> 4
5 roundUpTo:4 -> 8
6 roundUpTo:4
7 roundUpTo:4
8 roundUpTo:4
(3@4) roundUpTo:8
(3@4) roundUpTo:(5 @ 4)
(3@3) roundUpTo:(5 @ 4)
|
-
rounded
-
return the receiver rounded to the nearest integer
-
roundedToScale
-
I am already rounded to my scale, so this is a noop.
This is provided for protocol compatibility with ScaledDecimals
-
truncateTo: aNumber
-
return the receiver truncated (towards zero) to multiples of aNumber;
bad name; should be called truncatedTo:aNumber
Usage example(s):
truncate to multiples of 4
123.456 truncateTo:4 => 120
124.456 truncateTo:4 => 124
125.456 truncateTo:4 => 124
truncate to multiples of 2
122.456 truncateTo:2
123.456 truncateTo:2
124.456 truncateTo:2
normal truncate
123.456 truncateTo:1
124.456 truncateTo:1
truncate to decimal digits
123.456 truncateTo:0.1 => 123.4
123.987 truncateTo:0.1 => 123.9
123.456 truncateTo:0.01 => 123.45
123.456 truncateTo:0.001 => 123.456
|
-
truncated
-
return the receiver truncated towards zero
|