|
Class: Number
Object
|
+--Magnitude
|
+--ArithmeticValue
|
+--Number
|
+--Complex
|
+--FixedDecimal
|
+--Fraction
|
+--Integer
|
+--LimitedPrecisionReal
|
+--MetaNumber
- Package:
- stx:libbasic
- Category:
- Magnitude-Numbers
- Version:
- rev:
1.475
date: 2024/04/25 13:49:01
- user: stefan
- file: Number.st directory: libbasic
- module: stx stc-classLibrary: libbasic
abstract superclass for all kinds of numbers
[class variables:]
DecimalPointCharacterForPrinting <Character> used when printing
DecimalPointCharactersForReading <Collection of Character> accepted as decimalPointChars when reading
DefaultDisplayRadix the radix in which integers present their
displayString (which is used in inspectors)
If you are to look at many hex numbers, bitmasks
etc. you may set this to 2 or 16.
(avoids typing printStringRadix:.. all the time
- I know - I am lazy ;-). Default is 10.
copyrightCOPYRIGHT (c) 1988 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
-
readIntegerFrom: aStream radix: radix
-
for VisualWorks compatibility
Javascript support
-
MAX_VALUE
( an extension from the stx:libjavascript package )
-
this is for JavaScript's Number.MAX_VALUE.
In expecco/stx-JS, there is no MAX_VALUE;
return something useful (simulate 64bits)
Usage example(s):
JavaScriptParser
evaluate:'Number.MAX_VALUE;'
|
-
MIN_VALUE
( an extension from the stx:libjavascript package )
-
this is for JavaScript's Number.MIN_VALUE.
In expecco/stx-JS, there is no MIN_VALUE;
return something useful (simulate 64bits)
Usage example(s):
JavaScriptParser
evaluate:'Number.MIN_VALUE;'
|
-
NEGATIVE_INFINITY
( an extension from the stx:libjavascript package )
-
this is for JavaScript's Number.NEGATIVE_INFINITY.
Return a special 'negative infinity' float value
Usage example(s):
JavaScriptParser
evaluate:'Number.NEGATIVE_INFINITY;'
|
-
NaN
( an extension from the stx:libjavascript package )
-
return the special 'not a number' float value
Usage example(s):
JavaScriptParser
evaluate:'Number.NaN;'
|
-
POSITIVE_INFINITY
( an extension from the stx:libjavascript package )
-
this is for JavaScript's Number.POSITIVE_INFINITY.
Return the special 'positive infinity' float value
Usage example(s):
JavaScriptParser
evaluate:'Number.POSITIVE_INFINITY;'
|
-
isFinite: aNumber
( an extension from the stx:libjavascript package )
-
this is for JavaScript's Number.isFinite().
In Smalltalk, you would ask the number.
Return true if the argument is not infinite
-
isInteger: something
( an extension from the stx:libjavascript package )
-
this is for JavaScript's Number.isInteger().
Return true, if something is an integer (or a float which is equal to its truncated value).
Slightly different from Smalltalk's isInteger instance message.
For JS compatibility
-
isNaN: aNumber
( an extension from the stx:libjavascript package )
-
this is for JavaScript's Number.isNaN().
Return true if the argument is NaN
-
js_new: argument
( an extension from the stx:libjavascript package )
-
this is for JavaScript's new Number().
-
parseFloat: aString
( an extension from the stx:libjavascript package )
-
this is for JavaScript's Number.parseFloat().
Read a float from aString.
Reads up to the first non-number character.
If there is no number at all at the beginning of aString, returns NaN
-
parseInt: aString
( an extension from the stx:libjavascript package )
-
this is for JavaScript's Number.parseInt().
Read an integer from aString.
Reads up to the first non-number character.
If there is no number at all at the beginning of aString, returns NaN
coercing & converting
-
nonFiniteCoercionFrom: aNumber to: rslt
-
conversion resulted in a non-finite result.
This common code handles NaN and infinities,
and raises an error otherwise.
If the error is proceeded, the non-finite result is returned.
constants
-
e
-
return the closest approximation of the irrational number e
** This method must be redefined in concrete classes (subclassResponsibility) **
-
eDigits
-
return th printString of the irrational number e,
with enough digits so that instances with different precision can read from it
-
halfPi
-
return Pi/2 in my representation (and accuracy).
-
halfPiDigits
-
return the printString of the irrational number pi/2,
with enough digits so that instances with different precision can read from it
-
halfPiNegative
-
return -Pi/2 in my representation (and accuracy).
-
halfpi
-
obsolete name for backward compatibility
return -Pi/2 in my representation (and accuracy).
-
halfpiNegative
-
obsolete name for backward compatibility
return -Pi/2 in my representation (and accuracy).
-
i
-
return the imaginary unit i
Usage example(s):
1 + Number i -> (1+1i)
Number i + 10 -> (10+1i)
Number i * Number i -> -1
|
Usage example(s):
Modified (format): / 10-12-2020 / 22:22:55 / cg
|
-
ln10
-
return ln(10) in my representation (and accuracy).
** This method must be redefined in concrete classes (subclassResponsibility) **
-
ln10Digits
-
return th printString of the irrational number ln(10),
with enough digits so that instances with different precision can read from it
-
ln2
-
return ln(2) in my representation (and accuracy).
** This method must be redefined in concrete classes (subclassResponsibility) **
-
ln2Digits
-
return th printString of the irrational number ln(2),
with enough digits so that instances with different precision can read from it
-
negativeZero
-
if my concrete class supports it, return a zero with negative sign.
Otherwise just return zero
Usage example(s):
FloatE negativeZero
FloatD negativeZero
FloatQ negativeZero
LargeFloat negativeZero
|
-
phi
-
return Phi in my representation (and accuracy).
Usage example(s):
Usage example(s):
Float phix
LongFloat phix
LargeFloat phix
QuadFloat phix
|
-
phiDigits
-
return the printString of the irrational number phi,
with enough digits so that instances with different precision can read from it
-
pi
-
return Pi in my representation (and accuracy).
This is a fallback for all classes which have no special
representation for Pi (or which cannot represent it)
-
piDigits
-
return th printString of the irrational number pi,
with enough digits so that instances with different precision can read from it
-
piNegative
-
return -Pi in my representation (and accuracy).
-
sqrt2
-
return sqrt(2) in my representation (and accuracy).
** This method must be redefined in concrete classes (subclassResponsibility) **
-
sqrt2Digits
-
return th printString of the irrational number sqrt(2),
with enough digits so that instances with different precision can read from it
-
sqrt3
-
return sqrt(3) in my representation (and accuracy).
** This method must be redefined in concrete classes (subclassResponsibility) **
-
sqrt3Digits
-
return th printString of the irrational number sqrt(3),
with enough digits so that instances with different precision can read from it
-
twoPi
-
return Pi*2 in my representation (and accuracy).
-
twoPiNegative
-
return -Pi*2 in my representation (and accuracy).
constants & defaults
-
decimalPointCharacter
-
printed
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
decimalPointCharacter: aCharacter
-
printed
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
decimalPointCharacterForPrinting
-
printed
-
decimalPointCharacterForPrinting: aCharacter
-
printed
Usage example(s):
1.5 printString
Number decimalPointCharacterForPrinting:$,.
1.5 printString
Number decimalPointCharacterForPrinting:$..
|
-
decimalPointCharacters
-
accepted when converting from a string
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
decimalPointCharacters: aCollectionOfCharacters
-
accepted when converting from a string
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
decimalPointCharactersForReading
-
default when converting from a string
Usage example(s):
1.5 printString
Number decimalPointCharactersForReading:#( $. $,) .
Number fromString:'1.5'.
Number fromString:'1,5'.
Number decimalPointCharactersForReading:#( $. ).
|
-
decimalPointCharactersForReading: aCollectionOfCharacters
-
accepted when converting from a string
Usage example(s):
Number decimalPointCharactersForReading:#( $. $,) .
Number fromString:'1.5'.
Number fromString:'1,5'.
Number decimalPointCharactersForReading:#( $. ).
|
-
nameOfInf
-
adjustable printname of infinity;
some prefer INF, some inf.
You can configure this by setting this variable
-
nameOfNaN
-
adjustable printname of NaN;
some prefer NAN, some nan and some even NaN.
You can configure this by setting this variable
error reporting
-
errorInfiniteArgument: receiver selector: selector
-
Number errorInfiniteArgument:Float infinity selector:'ln'
-
errorNaNArgument: receiver selector: selector
-
Number errorNaNArgument:Float NaN selector:'ln'
-
errorUnsupported
-
you may proceed from this error, to get an alternative representation result
(of course, maybe with with less than the expected precision)
-
raise: aSignalSymbolOrErrorClass receiver: someNumber selector: sel arg: arg errorString: text
-
ST-80 compatible signal raising. Provided for public domain numeric classes
Usage example(s):
Number
raise:#domainErrorSignal
receiver:1.0
selector:#sin
arg:nil
errorString:'foo bar test'
|
-
raise: aSignalSymbolOrErrorClass receiver: someNumber selector: sel errorString: text
-
ST-80 compatible signal raising. Provided for public domain 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'
|
instance creation
-
coerce: aNumber
-
convert the argument aNumber into an instance of the receiver (class) and return it.
-
fastFromString: aString
-
return the next Float, Integer or ShortFloat from the string.
No spaces are skipped.
This is a specially tuned entry (using a low-level C-call), which
returns garbage if the argument string is not a valid float number.
It has been added to allow high speed string decomposition into numbers,
especially for mass-data.
Usage example(s):
Float fromString:'12345.0'
Float fastFromString:'12345.0'
Integer fromString:'12345'
Integer fastFromString:'12345'
should be roughly 10times faster than the general method:
Time millisecondsToRun:[
100000 timesRepeat:[ Float fromString:'12345.0' ]
].
Time millisecondsToRun:[
100000 timesRepeat:[ Float fastFromString:'12345.0' ]
].
Time millisecondsToRun:[
100000 timesRepeat:[ Integer fromString:'12345' ]
].
Time millisecondsToRun:[
100000 timesRepeat:[ Integer fastFromString:'12345' ]
].
|
-
fastFromString: aString at: startIndex
-
return the next Float, Integer or ShortFloat from the string.
No spaces are skipped.
Returns zero, if there is no valid number at the startIndex.
Redefined for speed in subclasses.
This is the fallback handling nan and inf for the specially tuned entries (using a low-level C-call), which
which return garbage if the argument string is not a valid number.
Usage example(s):
Integer fromString:'nan'
Integer fastFromString:'nan' at:1
Integer fastFromString:'inf' at:1
Float fromString:'12345.0'
Float fastFromString:'xxx12345.0' at:4
FixedPoint fromString:'12345.4'
FixedPoint fastFromString:'xxx12345.4' at:4
Fraction fromString:'12345.4'
Fraction fastFromString:'xxx12345.4' at:4
Integer fromString:'12345'
Integer fastFromString:'xxx12345' at:4
should be roughly 10times faster than the general method:
Time millisecondsToRun:[
100000 timesRepeat:[ Float fromString:'12345.0' ]
].
Time millisecondsToRun:[
100000 timesRepeat:[ Float fastFromString:'12345.0' ]
].
Time millisecondsToRun:[
100000 timesRepeat:[ Integer fromString:'12345' ]
].
Time millisecondsToRun:[
100000 timesRepeat:[ Integer fastFromString:'12345' ]
].
|
-
forNonFiniteNumber: aNumber
-
common code to create an instance corresponding to aNumber,
which must be one of NaN, +inf or -inf.
-
fromNumber: aNumber
-
return aNumber coerced to myself
-
fromString: aString
-
return a number by reading from aString.
In contrast to readFrom:, no garbage is allowed after the number.
I.e. the string must contain exactly one valid number (with optional separators around)
Usage example(s):
Number fromString:'12345'
Number fromString:'abc'
Number fromString:'1abc' -> raises an error
Number readFrom:'1abc' -> reads a 1
Number readFrom:'10/2' -> reads a 10
Number fromString:'10/2' -> raises an error
Number fromString:'(1/2)' -> reads a fraction
Number readFrom:'(1/2)' -> reads a fraction
Number readFrom:'(10/2)' -> reads a 5
'12345' asNumber
|
-
fromString: aString decimalPointCharacter: decimalPointCharacter
-
return a number by reading from aString.
In contrast to readFrom:, no garbage is allowed after the number.
I.e. the string must contain exactly one valid number (with optional separators around)
Usage example(s):
Number fromString:'12345.99' decimalPointCharacter:$. => 12345.99
Number fromString:'12345,99' decimalPointCharacter:$, => 12345.99
Number fromString:'12345,99e3' decimalPointCharacter:$, => 12345990.0
ScaledDecimal fromString:'12345,99' decimalPointCharacter:$, => 12345.99
Number fromString:'aaa,99' decimalPointCharacter:$, => error
Number fromString:'123,99aaa' decimalPointCharacter:$, => error
|
-
fromString: aString decimalPointCharacter: decimalPointCharacter onError: exceptionBlock
-
return a number by reading from aString.
In contrast to readFrom:, no garbage is allowed after the number.
I.e. the string must contain exactly one valid number (with optional separators around)
Usage example(s):
Number fromString:'12,345' decimalPointCharacter:',' onError:0
Number fromString:'12,345' decimalPointCharacter:$, onError:0
Number fromString:'12,345,456' decimalPointCharacter:$. thouseandsSeparator:$, onError:0
Number fromString:'12,345,45' decimalPointCharacter:$. thouseandsSeparator:$, onError:0
|
-
fromString: aString decimalPointCharacter: decimalPointCharacter thousandsSeparator: thousandsSeparator onError: exceptionBlock
-
return a number by reading from aString.
In contrast to readFrom:, no garbage is allowed after the number.
I.e. the string must contain exactly one valid number (with optional separators around)
Usage example(s):
Number fromString:'12,345' decimalPointCharacter:',' onError:0
Number fromString:'12,345' decimalPointCharacter:$, onError:0
Number fromString:'12345,456' decimalPointCharacter:$. thousandsSeparator:$, onError:0
Number fromString:'12,345,456' decimalPointCharacter:$. thousandsSeparator:$, onError:0
Number fromString:'12,345,456,789' decimalPointCharacter:$. thousandsSeparator:$, onError:0
Number fromString:'12,345,456,789.89' decimalPointCharacter:$. thousandsSeparator:$, onError:0
Number fromString:'12.345.456.789,89' decimalPointCharacter:$, thousandsSeparator:$. onError:0
these report an error:
Number fromString:'12,345,45' decimalPointCharacter:$. thousandsSeparator:$, onError:0
Number fromString:'12.345.456.789' decimalPointCharacter:$. thousandsSeparator:$, onError:0
Number fromString:'12.345.456.78' decimalPointCharacter:$. thousandsSeparator:$, onError:0
|
-
fromString: aString decimalPointCharacters: decimalPointCharacters
-
return a number by reading from aString.
In contrast to readFrom:, no garbage is allowed after the number.
I.e. the string must contain exactly one valid number (with optional separators around)
Usage example(s):
Number fromString:'12345'
Number fromString:'abc'
Number fromString:'1abc'
'12345' asNumber
|
-
fromString: aString decimalPointCharacters: decimalPointCharacters onError: exceptionBlock
-
return a number by reading from aString.
In contrast to readFrom:, no garbage is allowed after the number.
I.e. the string must contain exactly one valid number (with optional separators around)
Usage example(s):
Number fromString:'12345' onError:0
Number fromString:'12,345' decimalPointCharacters:',' onError:0
Number fromString:'12,345' decimalPointCharacters:',' onError:0
Number fromString:'fooBarBaz' onError:0
Number fromString:'123fooBarBaz' onError:0
Number fromString:'123,fooBarBaz' decimalPointCharacters:',' onError:0
|
-
fromString: aString decimalPointCharacters: decimalPointCharacters thousandsSeparator: thousandsSeparator onError: exceptionBlock
-
return a number by reading from aString.
In contrast to readFrom:, no garbage is allowed after the number.
I.e. the string must contain exactly one valid number (with optional separators around)
Usage example(s):
Number fromString:'12345' onError:0
Number fromString:'12,345' decimalPointCharacters:',' onError:0
Number fromString:'12,345' decimalPointCharacters:',' onError:0
Number fromString:'fooBarBaz' onError:0
Number fromString:'123fooBarBaz' onError:0
Number fromString:'123,fooBarBaz' decimalPointCharacters:',' onError:0
|
-
fromString: aString onError: exceptionBlock
-
return a number by reading from aString.
In contrast to readFrom:, no garbage is allowed after the number.
I.e. the string must contain exactly one valid number (with optional separators around)
Usage example(s):
Number fromString:'12345' onError:0
Number fromString:'fooBarBaz' onError:0
Number fromString:'123fooBarBaz' onError:0
|
-
newFrom: aNumber
-
this allows for as: to be used for conversion
-
readFrom: aStringOrStream decimalPointCharacter: decimalPointCharacter
-
return the next Number from the (character-)stream aStream;
skipping all whitespace first.
Return the value of exceptionBlock, if no number can be read.
This method is less strict than the smalltalk number reader; it
allows for prefixed + and also allows missing fractional part after eE.
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
Usage example(s):
Number readFrom:'0' decimalPointCharacter:$.
Number readFrom:'123.456' decimalPointCharacter:$.
Number readFrom:'123,456' decimalPointCharacter:$,
|
-
readFrom: aStringOrStream decimalPointCharacter: decimalPointCharacter onError: exceptionBlock
-
return the next Number from the (character-)stream aStream;
skipping all whitespace first.
Return the value of exceptionBlock, if no number can be read.
This method is less strict than the Smalltalk number reader;
it allows for prefixed + and also allows missing fractional part after eE.
It supports the regular Smalltalk radix prefix xr.
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
Notice (see examples below):
if sent to Number, it will decide which type of number to return (depending on the exponent character);
if sent to a concrete number-class, an instance of that class will be returned (independent of the exponent character)
Usage example(s):
Number readFrom:(ReadStream on:'54.32e-01') decimalPointCharacter:$. onError:[self halt].
Number readFrom:(ReadStream on:'54,32e-01') decimalPointCharacter:$, onError:[self halt].
|
-
readFrom: aStringOrStream decimalPointCharacters: decimalPointCharacters
-
return the next Number from the (character-)stream aStream;
skipping all whitespace first.
Return the value of exceptionBlock, if no number can be read.
This method is less strict than the smalltalk number reader; it
allows for prefixed + and also allows missing fractional part after eE.
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
Usage example(s):
Number readFrom:'123.456' decimalPointCharacters:'.'
Number readFrom:'123,456' decimalPointCharacters:'.,'
Number readFrom:'123,456' decimalPointCharacters:'.'
|
-
readFrom: aStringOrStream decimalPointCharacters: decimalPointCharacters allowCStyle: allowCStyle onError: exceptionBlock
-
return the next Number from the (character-)stream aStream;
skipping all whitespace first.
Return the value of exceptionBlock, if no number can be read.
This method is less strict than the Smalltalk number reader;
it allows for prefixed + and also allows missing fractional part after eE.
It supports 0x, 0o and 0b prefixes (hex, octal and binary)
and the regular Smalltalk radix prefix xr.
If also allows for strings like '1.0×1015' to be read (as 1E+15).
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
Notice (see examples below):
if sent to Number, it will decide which type of number to return (depending on the exponent character);
if sent to a concrete number-class, an instance of that class will be returned (independent of the exponent character)
Usage example(s):
Number readFrom:(ReadStream on:'1.234.567,99')
decimalPointCharacter:$,
thousandsSeparator:$.
onError:[self halt].
|
-
readFrom: aStringOrStream decimalPointCharacters: decimalPointCharacters onError: exceptionBlock
-
return the next Number from the (character-)stream aStream;
skipping all whitespace first.
Return the value of exceptionBlock, if no number can be read.
This method is less strict than the Smalltalk number reader;
it allows for prefixed + and also allows missing fractional part after eE.
It supports the regular Smalltalk radix prefix xr.
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
Notice (see examples below):
if sent to Number, it will decide which type of number to return (depending on the exponent character);
if sent to a concrete number-class, an instance of that class will be returned (independent of the exponent character)
Usage example(s):
Number readFrom:(ReadStream on:'54.32e-01') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0f') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0e') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0q') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0d') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0s') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.01s') decimalPointCharacters:'.' onError:[self halt].
Float readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345678901234567890')
Number readFrom:(ReadStream on:'12345678901234567890.0')
Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890')
Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
Number readFrom:'16rAAAAFFFFAAAAFFFF'
Number readFrom:'16r100A'
Number readFrom:'16r100a'
Number readFrom:'0.000001'
'+00000123.45' asNumber
Number readFrom:'(1/3)'
Number readFrom:'(-1/3)'
Number readFrom:'(1/-3)'
Number readFrom:'-(1/3)'
Number readFrom:'-(-1/3)'
Number readFrom:'(-1/3'
Number readFrom:'99s'
Number readFrom:'99.00s'
Number readFrom:'99.0000000s'
Number readFrom:'.0000000s'
Number readFrom:'.0000000q'
Number readFrom:'.0000000f'
Number readFrom:'.0000000e'
Number readFrom:'.0000000s1'
Number readFrom:'.0000000q1'
Number readFrom:'.0000000f1'
Number readFrom:'.0000000e1'
LongFloat readFrom:'.00000001'
Number readFrom:'.00000000000001'
Number readFrom:'.001'
ShortFloat readFrom:'.001'
Number readFrom:'123garbage' -> returns 123
Number fromString:'123garbage' -> raises an error
DecimalPointCharactersForReading := #( $. $, ).
Number readFrom:'99,00'
DecimalPointCharactersForReading := #( $. ).
Number readFrom:'99,00'
Number readFrom:'-(1d)'
|
-
readFrom: aStringOrStream decimalPointCharacters: decimalPointCharacters thousandsSeparator: thousandsSeparator allowCStyle: allowCStyle onError: exceptionBlock
-
return the next Number from the (character-)stream aStream;
skipping all whitespace first.
Return the value of exceptionBlock, if no number can be read.
This method is less strict than the Smalltalk number reader;
it allows for prefixed + and also allows missing fractional part after eE.
It supports 0x, 0o and 0b prefixes (hex, octal and binary)
and the regular Smalltalk radix prefix xr.
If also allows for strings like '1.0×1015' to be read (as 1E+15).
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
Notice (see examples below):
if sent to Number, it will decide which type of number to return (depending on the exponent character);
if sent to a concrete number-class, an instance of that class will be returned (independent of the exponent character)
Usage example(s):
do not multiply by Fractions. The result is inaccurate in the last digit:
(Float fmin * 2) = (Number readFrom:(Float fmin * 2) storeString)
|
Usage example(s):
as in Number readFrom:'1.235×104'
|
Usage example(s):
Number readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'10e3') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'54.32e-01') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0f') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0e') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0q') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0d') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0s') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.01s') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345.0Q') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'123456.0Q') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345678901234567890.0Q') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345678901234567890.0q') decimalPointCharacters:'.' onError:[self halt].
Float readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12345678901234567890')
Number readFrom:(ReadStream on:'12345678901234567890.0')
Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890')
Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
Number readFrom:'16rAAAAFFFFAAAAFFFF'
Number readFrom:'16r100A'
Number readFrom:'16r100a'
Number readFrom:'16r-100A'
Number readFrom:'-16r100A'
Number readFrom:'0x100A'
Number readFrom:'-0x100A'
Number readFrom:'0x-100A'
Number readFrom:'0.000001'
'+00000123.45' asNumber
Number readFrom:'(1/3)'
Number readFrom:'(-1/3)'
Number readFrom:'(1/-3)'
Number readFrom:'-(1/3)'
Number readFrom:'-(-1/3)'
Number readFrom:'(-1/3'
Number readFrom:'99s'
Number readFrom:'99.00s'
Number readFrom:'99.0000000s'
Number readFrom:'0.0000000s'
Number readFrom:'.0000000s'
Number readFrom:'.0000000s1'
Number readFrom:'.0000000s4'
Number readFrom:'.3s'
Number readFrom:'0.3s'
Number readFrom:'.0000000e'
Number readFrom:'.0000000f'
Number readFrom:'.0000000q'
Number readFrom:'.0000000e1'
Number readFrom:'.0000000f1'
Number readFrom:'.0000000q1'
LongFloat readFrom:'.00000001'
Number readFrom:'.00000000000001'
Number readFrom:'.001'
ShortFloat readFrom:'.001'
Number readFrom:'123garbage' -> returns 123
Number fromString:'123garbage' -> raises an error
DecimalPointCharactersForReading := #( $. $, ).
Number readFrom:'99,00'
DecimalPointCharactersForReading := #( $. ).
Number readFrom:'99,00'
Number readFrom:'.' -> raises an error
Number readFrom:'.e' -> raises an error
Number readFrom:'.s'
Number readFrom:'123.4' 123.4 {Float}
Number readFrom:'123.4f' 123.4 {ShortFloat}
Number readFrom:'123.4e' 123.4 {Float}
Number readFrom:'123.4d' 123.4 {Float}
Number readFrom:'123.4q' 123.4 {LongFloat}
Number readFrom:'123.4Q' 123.3999999999998635757947341848414 {QuadFloat} (wrong!)
Number readFrom:'123.4QO' 123.4 {OctaFloat}
Number readFrom:'123.4QL' 123.4 {LargeFloat}
Number readFrom:'123.4QD' 123.40000000000000002220446049250313080847263336181640625 {QDouble} (wrong!)
Number readFrom:'123.4e2f' 1234.0 {ShortFloat}
Number readFrom:'123.4e2e' 1234.0 {Float}
Number readFrom:'123.4e2d' 1234.0 {Float}
Number readFrom:'123.4e2q' 1234.0 {LongFloat}
Number readFrom:'123.4e2Q' 12339.9999999999863575794765824 {QuadFloat} (wrong!)
Number readFrom:'123.4e2QO' 12340.0 {OctaFloat}
Number readFrom:'123.4e2QL' 12340.0 {LargeFloat}
Number readFrom:'123.4e2QD' 12340.0 {QDouble}
|
-
readFrom: aStringOrStream decimalPointCharacters: decimalPointCharacters thousandsSeparator: thousandsSeparator onError: exceptionBlock
-
return the next Number from the (character-)stream aStream;
skipping all whitespace first.
Return the value of exceptionBlock, if no number can be read.
This method is less strict than the Smalltalk number reader;
it allows for prefixed + and also allows missing fractional part after eE.
It supports the regular Smalltalk radix prefix xr.
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
Notice (see examples below):
if sent to Number, it will decide which type of number to return (depending on the exponent character);
if sent to a concrete number-class, an instance of that class will be returned (independent of the exponent character)
Usage example(s):
Number readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
Number readFrom:(ReadStream on:'12,345.0') decimalPointCharacters:'.' thousandsSeparator:$, onError:[self halt].
Number readFrom:(ReadStream on:'12,1345.0') decimalPointCharacters:'.' thousandsSeparator:$, onError:[self halt].
|
-
readFrom: aStringOrStream onError: exceptionBlock
-
return the next Number from the (character-)stream aStream;
skipping all whitespace first; return the value of exceptionBlock,
if no number can be read.
This method is less strict than the smalltalk number reader; it
allows for prefixed + and also allows missing fractional part after eE.
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
Usage example(s):
Number readFrom:(ReadStream on:'54.32e-01') => 5.432
Number readFrom:(ReadStream on:'12345678901234567890') => 12345678901234567890
Number readFrom:(ReadStream on:'12345678901234567890.0') => 12345678901234567890.0
Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890') => 1.234567890123456789001234567890123456789e+19
Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') => 12297923206033637375
Number readFrom:'16rAAAAFFFFAAAAFFFF' => 12297923206033637375
Number readFrom:'0.000001' => 1e-06
'+00000123.45' asNumber => 123.45
Number readFrom:'0' => 0
Number readFrom:'99s2' => 99.00 (FixedPoint)
Number readFrom:'99s' Error
Number readFrom:'99.00s' => 99.00 (FixedPoint)
Number readFrom:'99.0000000s' => 99.0000000 (FixedPoint)
Number readFrom:'.0000000s' => 0.0000000
Number readFrom:'.0000000q' => 0.0 (Float80)
Number readFrom:'.0000000f' => 0.0 (Float32)
Number readFrom:'.0000000e' => 0.0
Number readFrom:'.0000000s1' => 0.0 (FixedPoint)
Number readFrom:'.0000000q1'
Number readFrom:'.0000000f1'
Number readFrom:'.0000000e1'
Number readFrom:'3+4i'
Number readFrom:'4i'
DecimalPointCharactersForReading := #( $. $, ).
Number readFrom:'99,00'
DecimalPointCharactersForReading := #( $. ).
Number readFrom:'99,00'
|
-
readNonImaginaryFrom: aStringOrStream onError: exceptionBlock
-
return the next non-imaginary Number from the (character-)stream aStream;
skipping all whitespace first; return the value of exceptionBlock,
if no number can be read.
This method is less strict than the smalltalk number reader; it
allows for prefixed + and also allows missing fractional part after eE.
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
-
readPossiblyComplexFrom: aStringOrStream onError: exceptionBlock
-
supports:
r + ni
r
ni
-
readSmalltalkSyntaxFrom: aStream
-
ST-80 compatibility (thanks to a note from alpha testers).
Read and return the next Number in Smalltalk syntax from the
(character-) aStream.
Returns nil if aStream contains no valid number.
Notice that ST/X supports C-style integers, which VW does not
Usage example(s):
Number readSmalltalkSyntaxFrom:'99d'
Number readSmalltalkSyntaxFrom:'99.00d'
Number readSmalltalkSyntaxFrom:'54.32e-01'
Number readSmalltalkSyntaxFrom:'12345678901234567890'
Number readSmalltalkSyntaxFrom:'16rAAAAFFFFAAAAFFFF'
Number readSmalltalkSyntaxFrom:'foobar'
Number readSmalltalkSyntaxFrom:'(1/10)'
Number readSmalltalkSyntaxFrom:'(1/0)'
Number readSmalltalkSyntaxFrom:'0xA0'
Number readSmalltalkSyntaxFrom:'0b1010'
Number readFrom:'(1/3)'
Number readFrom:'(-1/3)'
Number readFrom:'-(1/3)'
Number readFrom:'(1/-3)'
Number readFrom:'(-1/-3)'
Number readFrom:'-(-1/-3)'
Number readSmalltalkSyntaxFrom:'+00000123.45'
Number readFrom:'+00000123.45'
|s|
s := ReadStream on:'2.'.
Number readSmalltalkSyntaxFrom:s.
s next
|s|
s := ReadStream on:'2.0.'.
Number readSmalltalkSyntaxFrom:s.
s next
|
-
readSmalltalkSyntaxFrom: aStream onError: errorValue
-
ST-80 compatibility (thanks to a note from alpha testers)
read and return the next Number in smalltalk syntax from the
(character-) aStream.
Returns nil if aStream contains no valid number.
Usage example(s):
Number readSmalltalkSyntaxFrom:'foo' onError:123
Number readSmalltalkSyntaxFrom:'16r123' onError:-1
Number readSmalltalkSyntaxFrom:'0x123' onError:-1
Number readSmalltalkSyntaxFrom:'16r1.1' onError:-1
Number readSmalltalkSyntaxFrom:'10r1.1' onError:-1
Number readSmalltalkSyntaxFrom:'16r10.1' onError:-1
Number readSmalltalkSyntaxFrom:'10r10.1' onError:-1
Number readSmalltalkSyntaxFrom:'16r10.1e10' onError:-1
Number readSmalltalkSyntaxFrom:'10r10.1e10' onError:-1
|
misc
-
displayRadix: aNumber
-
being tired of always sending #printStringRadix: in the inspectors,
this allows you to change the default print radix for the displayString
method.
Usage example(s):
Integer displayRadix:16. 123456 inspect
Integer displayRadix:10. 123456 inspect
|
-
taylorSeriesIterationLimit
-
the max. number of terms to be computed when doing taylor series
approximations. These will stop and raise an error, when
a series approximation has not reached that precision
and that many terms have been computed.
The exception can be proceeded for more iterations
-
taylorSeriesIterationLimit: anInteger
-
the max. number of terms to be computed when doing taylor series
approximations. These will stop and raise an error, when
a series approximation has not reached that precision
and that many terms have been computed.
The exception can be proceeded for more iterations
private
-
readMantissaAndScaleFrom: aStream base: radix
-
helper for readFrom: -
return a tuple consisting of:
- the mantissa (post-decimal-point digits) from the (character-)stream aStream
as a float, longFloat (if more than 6 digits are given) or largeFloat (more than 15 digits)
- the mantissa as integer
- the scale (number of postDecimalPoint digits) is returned
(to support reading fixedPoint numbers and to not loose precision).
The integer mantissa is needed as we do not yet know the target type
(could be LongFloat or even QDouble).
i.e. If it turns out, that the number of digits is too many for Float precision,
the caller may still compute it using the numerator and the scale
with: numerator asHighPrecisionFloat / (radix raisedTo:scale).
No whitespace is skipped.
Usage example(s):
Number readMantissaAndScaleFrom:'234' readStream base:10. => #(0.234 234 3)
Number readMantissaAndScaleFrom:'2' readStream base:10. => #(0.2 2 1)
Number readMantissaAndScaleFrom:'234567' readStream base:10. => #(0.234567 234567 6)
Number readMantissaAndScaleFrom:'1234567' readStream base:10. => #(0.1234567 1234567 7)
Number readMantissaAndScaleFrom:'234000' readStream base:10. => #(0.234 234000 6)
Number readMantissaAndScaleFrom:'234' readStream base:10. => #(0.234 234 3)
Number readMantissaAndScaleFrom:'000234' readStream base:10. => #(0.000234 234 6)
Number readMantissaAndScaleFrom:'01' readStream base:10. => #(0.01 1 2)
Number readMantissaAndScaleFrom:'001' readStream base:10. => #(0.001 1 3)
Number readMantissaAndScaleFrom:'0001' readStream base:10. => #(0.0001 1 4)
Number readMantissaAndScaleFrom:'000000000000000000000000000024' readStream base:10. => #(2.4e-29 24 30)
Number readMantissaAndScaleFrom:'0000000000000000000000000000000000000000000024' readStream base:10. => #(2.4e-45 24 46)
Number readMantissaAndScaleFrom:(Number piDigits copyFrom:3) readStream base:10. => #(0.1415926535897932385 14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152 326)
Number readMantissaAndScaleFrom:'123456789012345678901234567890' readStream base:10.
Number readMantissaAndScaleFrom:'1234567890123456789012345678901234567890' readStream base:10.
Number readMantissaAndScaleFrom:'12345678901234567890' readStream base:10. => #(0.1234567890123456789 12345678901234567890 20)
Number readMantissaAndScaleFrom:'123456789012345' readStream base:10. => #(0.123456789012345 123456789012345 15)
Number readMantissaAndScaleFrom:'1234567890123456' readStream base:10. => #(0.1234567890123456 1234567890123456 16)
Number readFrom:'1.23456789012345678' readStream. => 1.23456789012345678
Number readFrom:'1.23456789012345678901' readStream. => 1.23456789012345678901
Number readFrom:'1.23456789012345678901234567' readStream. => 1.23456789012345678901234567
|
queries
-
epsilon
-
return the maximum relative spacing of instances of mySelf
(i.e. the value-delta of the least significant bit)
according to ISO C standard;
Ada, C, C++ and Python language constants;
Mathematica, MATLAB and Octave; and various textbooks
see https://en.wikipedia.org/wiki/Machine_epsilon
** This method must be redefined in concrete classes (subclassResponsibility) **
-
epsilonForCloseTo
-
return the epsilon used in the closeTo: comparison.
(useful would be something like self epsilon or epsilon*10,
but for Squeak compatibility.... - sigh)
-
isAbstract
-
Return if this class is an abstract class.
True is returned for Number here; false for subclasses.
Abstract subclasses must redefine this again.
-
isSupported
-
redefined in classes which are present, but not yet supported
Compatibility-Cuis
-
isWithin: count floatsFrom: anotherNumber
( an extension from the stx:libcompat package )
-
compatibility;
same as isAlmostEqualTo:aNumber nEpsilon:nE
Usage example(s):
1 isWithin:5 floatsFrom:1.000000000000001 -> true
1 isWithin:5 floatsFrom:1.00000000000001 -> false
1 asShortFloat isWithin:5 floatsFrom:1.000000000000001 asShortFloat -> true
1 asShortFloat isWithin:5 floatsFrom:1.00000000000001 asShortFloat -> true
1 asShortFloat isWithin:5 floatsFrom:1.0000000000001 asShortFloat -> true
1 asShortFloat isWithin:5 floatsFrom:1.0000001 asShortFloat -> true
1 asShortFloat isWithin:5 floatsFrom:1.000001 asShortFloat -> false
1 asLongFloat isWithin:5 floatsFrom:1.0000000000000001 asLongFloat -> true
1 asLongFloat isWithin:5 floatsFrom:1.000000000000001 asLongFloat -> false
1 asLongFloat isWithin:5 floatsFrom:1.00000000000001 asLongFloat -> false
1 asQuadFloat isWithin:5 floatsFrom:1.000000000000000000000001 asQuadFloat -> false
1 asQuadFloat isWithin:5 floatsFrom:1.00000000000000000001 asQuadFloat -> false
1 asQuadFloat isWithin:5 floatsFrom:1.0000000000000000001 asQuadFloat -> false
1 asQuadFloat isWithin:5 floatsFrom:1.000000000000000001 asQuadFloat -> false
1 asQuadFloat isWithin:5 floatsFrom:1.00000000000000001 asQuadFloat -> false
1 asQuadFloat isWithin:5 floatsFrom:1.0000000000000001 asQuadFloat -> false
1 asQuadFloat isWithin:5 floatsFrom:1.000000000000001 asQuadFloat -> false
|
Compatibility-Squeak
-
arcCosH
-
sigh: arc instead of area
-
arcCosh
-
sigh: arc instead of area
-
arcCotH
-
sigh: arc instead of area
-
arcCoth
-
sigh: arc instead of area
-
arcCscH
-
sigh: arc instead of area
-
arcCsch
-
sigh: arc instead of area
-
arcSecH
-
sigh: arc instead of area
-
arcSech
-
sigh: arc instead of area
-
arcSinH
-
sigh: arc instead of area (which is wrong, but seems to be used)
-
arcSinh
-
sigh: arc instead of area (which is wrong, but seems to be used)
-
arcTanH
-
sigh: arc instead of area
-
arcTanh
-
sigh: arc instead of area
-
asDuration
( an extension from the stx:libcompat package )
-
return an TimeDuration object from the receiver, taking the receiver
as number of seconds
-
asSmallAngleDegrees
( an extension from the stx:libcompat package )
-
Return the receiver normalized to lie within the range (-180, 180)
Usage example(s):
#(-500 -300 -150 -5 0 5 150 300 500 1200)
collect: [:n | n asSmallAngleDegrees]
|
-
cosH
-
sigh: upper vs. lowercase trailing H"
-
cotH
-
sigh: upper vs. lowercase trailing H"
-
cscH
-
sigh: upper vs. lowercase trailing H"
-
newTileMorphRepresentative
( an extension from the stx:libcompat package )
-
-
secH
-
sigh: upper vs. lowercase trailing H"
-
sinH
-
sigh: upper vs. lowercase trailing H"
-
sqrtWithErrorLessThan: epsilon
( an extension from the stx:libcompat package )
-
compute the square root, using the Newton method.
The approximated return value has an error less than the given epsilon.
Notice, that there is no speed advantage using this with Floats or Integers
within the float range (actually, there is quite a disavantage)
Usage example(s):
(2 asFixedPoint:4) sqrtWithErrorLessThan:0.001
|
-
stringForReadout
( an extension from the stx:libcompat package )
-
-
tanH
-
sigh: upper vs. lowercase trailing H"
Javascript support
-
js_typeof
( an extension from the stx:libjavascript package )
-
return a string describing what I am
-
toExponential
( an extension from the stx:libjavascript package )
-
return a string representing the number in exponential notation.
For full compatibility, return a plus in front of the exponent-character
Usage example(s):
JavaScriptParser evaluate:'(new Number(10000)).toExponential()'
JavaScriptParser evaluate:'(new Number(1.23456)).toExponential()'
JavaScriptParser evaluate:'(new Number(1.23456e-5)).toExponential()'
|
-
toExponential: nDigitsAfter
( an extension from the stx:libjavascript package )
-
return a string representing the number in exponential notation with nDigitsAfter
fractional digits
-
toExponential: nDigits _: nDigitsAfter
( an extension from the stx:libjavascript package )
-
return a string representing the number in exponential notation
-
toFixed
( an extension from the stx:libjavascript package )
-
return a string representing the number in fixed notation
Usage example(s):
JavaScriptParser evaluate:'(new Number(10000)).toFixed()'
JavaScriptParser evaluate:'(new Number(12.345)).toFixed()'
|
-
toFixed: nDigits
( an extension from the stx:libjavascript package )
-
return a string representing the number in fixed notation
approximation series
-
arcSin_withAccuracy: epsilon
-
compute the arcSine of the receiver using a power series approx.
-
arcTan_withAccuracy: epsilon
-
compute the arcTangent of the receiver using a taylor series approx.
Warning: this converges very slow
Usage example(s):
1.0 arcTan 0.785398
1q arcTan 0.785398163
1q arcTan_withAccuracy:1 0.666666667
1q arcTan_withAccuracy:0.1 0.744011544
1q arcTan_withAccuracy:0.01 0.790299653
1q arcTan_withAccuracy:0.001 0.785897165
1q arcTan_withAccuracy:1e-8 0.785398168
1q arcTan_withAccuracy:1e-20 -- not yet, converges very slow
wolfram:
0.4636476090008061162142562314612144020285370542861202638109330887...
0.5 arcTan 0.463647609000806
0.5q arcTan 0.4636476090008061162
0.5q arcTan_withAccuracy:1 0.458333333
0.5q arcTan_withAccuracy:0.1 0.458333333
0.5q arcTan_withAccuracy:0.01 0.4645833333333333333
0.5q arcTan_withAccuracy:0.001 0.4636842757936507937
0.5q arcTan_withAccuracy:1e-8 0.4636476080325976761
0.5q arcTan_withAccuracy:1e-20 0.4636476090008061161
0.5q arcTan_withAccuracy:1e-30 0.4636476090008061161
0.5 asLargeFloat arcTan_withAccuracy:1e-30 0.463647609001
(0.5 asLargeFloatPrecision:200) arcTan_withAccuracy:1e-50 0.463647609001
(0.5 asLargeFloatPrecision:1000) arcTan_withAccuracy:1e-100 0.463647609001
|
-
cbrt_withAccuracy: epsilon
-
compute the cubic root of the receiver using a newton approx.
Usage example(s):
8q cbrt 2.0
8q cbrt_withAccuracy:0.01 2.000004911675504018
8q cbrt_withAccuracy:0.0001 2.000000000012062239
8q cbrt_withAccuracy:0.0000001 2.0
8q cbrt_withAccuracy:0.0000000001 2.0
8q cbrt_withAccuracy:0.000000000001 2.0
8q cbrt_withAccuracy:LongFloat epsilon 2.0
8q asQDouble cbrt_withAccuracy:QDouble epsilon 2.0
27q cbrt_withAccuracy:0.01 3.000000541064176501
27q cbrt_withAccuracy:LongFloat epsilon 3.0
-27q cbrt_withAccuracy:LongFloat epsilon -3.0
MessageTally spyOn:[ |arg|
arg := 2 asLongFloat.
1000000 timesRepeat:[
arg cbrt_withAccuracy:0.000000000001
]
]
Time millisecondsToRun:[ |arg|
arg := 2 asLongFloat.
1000000 timesRepeat:[
arg cbrt_withAccuracy:0.000000000001
]
]
|
-
cbrt_withAccuracy: epsilon fromInitialGuess: guess
-
compute the cubic root of the receiver using a newton approx.
Usage example(s):
8q cbrt 2.0
8q cbrt_withAccuracy:0.01 2.000004911675504018
8q cbrt_withAccuracy:0.0001 2.000000000012062239
8q cbrt_withAccuracy:0.0000001 2.0
8q cbrt_withAccuracy:0.0000000001 2.0
8q cbrt_withAccuracy:0.000000000001 2.0
8q cbrt_withAccuracy:LongFloat epsilon 2.0
8q asQDouble cbrt_withAccuracy:QDouble epsilon 2.0
27q cbrt_withAccuracy:0.01 3.000000541064176501
27q cbrt_withAccuracy:LongFloat epsilon 3.0
-27q cbrt_withAccuracy:LongFloat epsilon -3.0
MessageTally spyOn:[ |arg|
arg := 2 asLongFloat.
1000000 timesRepeat:[
arg cbrt_withAccuracy:0.000000000001
]
]
Time millisecondsToRun:[ |arg|
arg := 2 asLongFloat.
1000000 timesRepeat:[
arg cbrt_withAccuracy:0.000000000001
]
]
|
-
cos_withAccuracy: epsilonWanted
-
compute the cosine of the receiver using a taylor series approx.
Usage example(s):
1.0 cos 0.540302
1.0 asLongFloat cos 0.5403023058681397174
1.0 asLongFloat cos_withAccuracy:1 0.5
1.0 asLongFloat cos_withAccuracy:0.1 0.541666667
1.0 asLongFloat cos_withAccuracy:0.01 0.540277778
1.0 asLongFloat cos_withAccuracy:0.001 0.540302579
1.0 asLongFloat cos_withAccuracy:1e-40 0.5403023058681397175
1.0 asQDouble cos 0.5403023058681396874081335957994
(1.0 asLargeFloatPrecision:200) cos
0.54030230586813971740093660744297660373231042061792222767009838
Wolfram:
0.5403023058681397174009366074429766037323104206179222276700972553......
|
-
cosh_withAccuracy: epsilonWanted
-
compute the hyperbolic cosine of the receiver using a power series approx.
Usage example(s):
1.0 cosh 1.54308
1.0q cosh_withAccuracy:1 1.5
1.0q cosh_withAccuracy:0.1 1.54308
1.0q cosh_withAccuracy:0.01 1.54308
1.0q cosh_withAccuracy:0.001 1.54308
1.0q cosh_withAccuracy:1e-40 -> 1.543080
(1.0 asLargeFloatPrecision:200) cosh_withAccuracy:1e-80
1.543080634815243778477905620757061682601529112365863704737399
Wolfram:
1.5430806348152437784779056207570616826015291123658637047374022147...
(10.0 asLargeFloatPrecision:200) cosh_withAccuracy:1e-80
11013.2329201033231397213760904378799634520614282374349704002
Wolfram:
11013.232920103323139721376090437879963452061428237434970400197807......
|
-
epsilon
-
return the maximum relative spacing of instances of mySelf
(i.e. the value-delta of the least significant bit).
according to ISO C standard;
Ada, C, C++ and Python language constants;
Mathematica, MATLAB and Octave; and various textbooks
see https://en.wikipedia.org/wiki/Machine_epsilon
-
erf_withAccuracy: epsilon
-
not a very efficient approximation here;
the approx. is inexact for larger receivers (>=7)
see eg. wikipedia
Usage example(s):
0.0 erf 0.0
0.0 erf_withAccuracy:1e-40 -3.00000007058543e-08
0.1 erf 0.112462916018285
0.1 erf_withAccuracy:1e-40 0.112462916018285
0.2 erf 0.222702589210478
0.2 erf_withAccuracy:1e-40 0.222702589210478
1.0 erf 0.842700792949715
1.0 erf_withAccuracy:1e-40 0.842700792949715
-1.0 erf_withAccuracy:1e-40 -0.842700792949715
2.0 erf 0.995322265018953
2.0 erf_withAccuracy:1e-40 0.995322265018953
3.0 erf 0.999977909503001
3.0 erf_withAccuracy:1e-40 0.999977909503024
3.0q erf_withAccuracy:1e-80 0.999977909503001429
3.0Q erf_withAccuracy:1e-80 0.99997790950300141455862722387
3.0QO erf_withAccuracy:1e-80 0.999977909503001414558627223870417679620152292912600750342761045160947
3.0QL erf_withAccuracy:1e-80 0.9999779095030014145586272238704176796201522929126007503426
wolfram: 0.9999779095030014145586272238704176796201522929126007503427610451...
4.0 erf 0.999999984582742
4.0q erf 0.9999999845827420997
4.0 erf_withAccuracy:1e-40 0.999999984582743
10.0 erf 1.0
10.0 erf_withAccuracy:1e-40 1.0
|
-
exp_withAccuracy: epsilon
-
compute e^x of the receiver using a taylor series approximation.
This method is only invoked for limitedPrecisionReal classes, which do not compute
exp themself (i.e. QDouble)
-
ln_withAccuracy: epsilon
-
compute ln of the receiver using a taylor series approx.
Usage example(s):
0.8q ln -0.2231435513142097003
0.8q ln_withAccuracy:1 -0.2231367169638774022
0.8q ln_withAccuracy:0.1 -0.2231367169638774022
0.8q ln_withAccuracy:0.01 -0.2231367169638774022
0.8q ln_withAccuracy:0.0000001 -0.2231435513083546378
0.8q ln_withAccuracy:1e-10 -0.2231435513141485206
0.8q ln_withAccuracy:1e-20 -0.2231435513142097002
0.8q ln_withAccuracy:1e-40 -0.2231435513142097002
0.8q ln_withAccuracy:2.0q class epsilon -0.2231435513142097002
(LargeFloat readFrom:'0.8' precision:400) ln -0.22314355131420975576629509030983450337460108554800721367128787248739174376826833341840722410034223571596334098057419143246
Wolfram says:
-0.2231435513142097557662950903098345033746010855480072136712878724873917437682683334184072241003422357159633409805741914323529...
2.0 ln 0.693147180559945
2.0q ln 0.6931471805599453094
2.0q ln_withAccuracy:1 0.6949363364285325478
2.0q ln_withAccuracy:0.1 0.6949363364285325478
2.0q ln_withAccuracy:0.01 0.6932902458935531239
2.0q ln_withAccuracy:0.0000001 0.6931471815716492569
2.0q ln_withAccuracy:1e-10 0.6931471805609741798
2.0q ln_withAccuracy:1e-20 0.693147180559945263
2.0q ln_withAccuracy:1e-40 0.693147180559945263
2.0q ln_withAccuracy:2.0q class epsilon 0.693147180559945263
0 ln_withAccuracy:1e-40 -> error
0.8q negated ln error
Number trapImaginary:[0.8q negated ln ] (-0.2231435513142097003+3.14159265358979i)
(2 ln_withAccuracy:1e-100) asFixedPoint:100
(2 asFixedPoint:200) ln_withAccuracy:(1/(10 raisedTo:200))
0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057068573368552023575813055703267075163507596193072757082837143519030703862389167347112335
(2 asFixedPoint:400) ln_withAccuracy:(1/(10 raisedTo:400))
0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057068573368552023575813055703267075163507596193072757082837143519030703862389167347112335 01153644979552391204751726815749320651555247341395258829504530070953263666426541042391578149520437404303855008019441706416715186447128399681717845469570262716310645461502572074024816377733896385506953
(2.0 asQDouble ln_withAccuracy:QDouble epsilon) printfPrintString:'%60.58f'
0.69314718055994 52709398341558750792990469129794959648865081'
'0.6931471805599452245588978789490895638089716177573625053064'
Wolfram says:
0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057068573368552023575813055703267075163507596193072757082837143519030703862389167347112335 01153644979552391204751726...
|
-
noConvergenceError: fnName
-
-
nthRoot: n withAccuracy: epsilon
-
compute nth root of the receiver using a newton approx.
Usage example(s):
8q nthRoot:3 withAccuracy:0.01 2.00000002488636242
8q nthRoot:3 withAccuracy:0.0001 2.00000000000000031
8q nthRoot:3 withAccuracy:0.0000001 2.00000000000000031
8q nthRoot:3 withAccuracy:0.0000000001 2.0
8q nthRoot:3 withAccuracy:0.000000000001 2.0
8q nthRoot:3 withAccuracy:LongFloat epsilon 2.0
27q nthRoot:3 withAccuracy:0.01 3.000000081210202031
27q nthRoot:3 withAccuracy:LongFloat epsilon 3.0
-27q nthRoot:3 withAccuracy:LongFloat epsilon -3.0
10000q nthRoot:5 withAccuracy:1e-18 -> 6.309573444801932495
100000q nthRoot:5 withAccuracy:1e-18 -> 10.0
(10000 asQDouble nthRoot:5) printfPrintString:'%70.68f'
6.30957344480193249434360136622343864672945257188228724527729528834741'
actual result (Mathematica):
6.309573444801932494343601366223438646729452571882287245277...
|
-
sin_withAccuracy: epsilonWanted
-
compute the sine of the receiver using a taylor series approx.
Usage example(s):
0.0 asOctaFloat sin 0.0
0.0 asQuadFloat sin 0.0
0.0 asIEEEFloat sin 0.0
1.0 sin 0.841470984807897
1.0q sin 0.8414709848078965067
1.0q sin_withAccuracy:1 0.8416666666666666666
1.0q sin_withAccuracy:0.1 0.8416666666666666666
1.0q sin_withAccuracy:0.01 0.8416666666666666666
1.0q sin_withAccuracy:0.001 0.8414682539682539682
1.0q sin_withAccuracy:1e-20
1.0q sin_withAccuracy:1e-40 0.8414709848078965066
1.0q sin_withAccuracy:1e-80 0.8414709848078965066
1.0q sin_withAccuracy:1e-80 0.8414709848078965066
(1.0 asLargeFloatPrecision:200) sin_withAccuracy:1e-80
0.8414709848078965066525023216302989996225630607983710656727508
wolfram:
0.8414709848078965066525023216302989996225630607983710656727517099...
|
-
sinh_withAccuracy: epsilonWanted
-
compute the hyperbolic sine of the receiver using a power series approx.
Usage example(s):
10 sinh 11013.2328747034
10 asQuadFloat sinh 11013.2329
10 asOctaFloat sinh 11013.232875
100 sinh 1.34405857090807e+43
100 asQuadFloat sinh 1.34405857e43
100 asOctaFloat sinh 1.3440585709e43
1000 asLongFloat sinh 9.850355570085235467e+433
1000 asQuadFloat sinh out of range error
1000 asOctaFloat sinh out of range error
1.0 asShortFloat sinh 1.1752011936438
1.0 sinh 1.1752011936438
1q sinh 1.175201193643801457
1.0 asLongFloat sinh 1.175201193643801457
1.0 asQuadFloat sinh 1.17520119
1.0 asOctaFloat sinh 1.1752011936
(1.0 asLargeFloatPrecision:200) sinh 1.175201193644
1q sinh_withAccuracy:1 1.16666667
1q sinh_withAccuracy:0.1 1.175
1q sinh_withAccuracy:0.01 1.175
1q sinh_withAccuracy:0.001 1.17519841
1q sinh_withAccuracy:1e-40 1.17520119
(1.0 asLargeFloatPrecision:200) sinh_withAccuracy:1e-80
1.175201193643801456882381850595600815155717981334095870229565
wolfram:
1.1752011936438014568823818505956008151557179813340958702295654130...
(10.0 asLargeFloatPrecision:200) sinh_withAccuracy:1e-80
11013.23287470339337723652455484636440290145119031934610383517
wolfram:
11013.232874703393377236524554846364402901451190319346103835228548...
|
-
sqrt_withAccuracy: epsilon
-
compute square root of the receiver using newton-raphson/heron algorithm
Usage example(s):
2 sqrt 1.4142135623731 - computed by CPU/FPU
200000000 sqrt
2q sqrt 1.414213562373095049 - computed by CPU/FPU
2q sqrt_withAccuracy:0.01 1.414215686274509804 - computed by Smalltalk
2q sqrt_withAccuracy:0.0001 1.414213562374689911
2q sqrt_withAccuracy:0.0000001 1.414213562373095049
2q sqrt_withAccuracy:0.0000000001 1.414213562373095049
2q sqrt_withAccuracy:0.000000000001 1.414213562373095049
2q sqrt_withAccuracy:LongFloat epsilon 1.414213562373095049
(2 asFixedDecimal:300) sqrt 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641572735013846230912297024924836055850737212644121497099935831413222665927505592755799950501152782060571470109559971605970274534596862014728517418640889198609552329230484308714321450839762603627995251407990
(4 sqrt_withAccuracy:Integer epsilon) asFloat
MessageTally spyOn:[ |arg|
arg := 2 asLongFloat.
1000000 timesRepeat:[
arg sqrt_withAccuracy:0.000000000001
]
]
Time millisecondsToRun:[ |arg|
arg := 2 asLongFloat.
1000000 timesRepeat:[
arg sqrt_withAccuracy:0.000000000001
]
]
|
-
sqrt_withAccuracy: epsilon fromInitialGuess: guess
-
compute square root of the receiver using newton-raphson/heron algorithm
Usage example(s):
2 sqrt 1.4142135623731
2q sqrt 1.414213562373095049
2q sqrt_withAccuracy:0.01 1.414215686274509804
2q sqrt_withAccuracy:0.0001 1.414213562374689911
2q sqrt_withAccuracy:0.0000001 1.414213562373095049
2q sqrt_withAccuracy:0.0000000001 1.414213562373095049
2q sqrt_withAccuracy:0.000000000001 1.414213562373095049
2q sqrt_withAccuracy:LongFloat epsilon 1.414213562373095049
(2 asQDouble sqrt_withAccuracy:LongFloat epsilon) printfPrintString:'%70.68f'
1.41421356237309504880168872420969807856967187537723400156101313309966
(4 sqrt_withAccuracy:Integer epsilon) asFloat
-2q sqrt_withAccuracy:0.0000001 -> error
Number trapImaginary:[-2q sqrt_withAccuracy:0.0000001] -> (0+1.414213562373095049i)
MessageTally spyOn:[ |arg|
arg := 2 asLongFloat.
1000000 timesRepeat:[
arg sqrt_withAccuracy:0.000000000001
]
]
Time millisecondsToRun:[ |arg|
arg := 2 asLongFloat.
1000000 timesRepeat:[
arg sqrt_withAccuracy:0.000000000001
]
]
|
-
tan_withAccuracy: epsilon
-
compute the tangens of the receiver using a taylor series approx.
Usage example(s):
0.5 tan 0.546302
0.5q tan 0.54630249
0.5q tan_withAccuracy:1 0.541666667
0.5q tan_withAccuracy:0.1 0.541666667
0.5q tan_withAccuracy:0.01 0.545833333
0.5q tan_withAccuracy:0.001 0.54625496
0.5q tan_withAccuracy:1e-15 0.54630249
0.5q tan_withAccuracy:1e-40 0.5463024898437905132
(0.5 asLargeFloatPrecision:100) tan
0.54630248984379051325517946577959
(0.5 asLargeFloatPrecision:200) tan
0.54630248984379051325517946578028538329755172017979124616408949
(0.5 asLargeFloatPrecision:400) tan
0.546302489843790513255179465780285383297551720179791246164091385 83432359047976386453016147931027794804955641807727198401039
wolfram:
0.546302489843790513255179465780285383297551720179791246164091385 9329075105180258157151806482706562185891048626002641142654932300...
(0.1 asLargeFloatPrecision:400) tan
0.10033467208545055066507850254801492712782258228855078633976653427797263386206757470626911032620832439612609916501210025027
(0.1 asQuadFloat) tan
0.1003346721
(0.1 asOctaFloat) tan
0.100334672085
(0.1 asQDouble) tan
0.10033467209
|
-
ulp
-
answer the distance between me and the next representable number;
mhmh this really ought to be redefined;
I am not sure if this makes a good fallback default
Usage example(s):
1.0 asShortFloat ulp 1.192093e-07
1.0 asShortFloat asIEEEFloat ulp
10.0 asShortFloat asIEEEFloat ulp
PrintfScanf printf:'%g' on:Transcript argument:10.0 asShortFloat
PrintfScanf printf:'%g' on:Transcript argument:10.0 asShortFloat asIEEEFloat
|
coercing & converting
-
i
-
return a complex number, with the receiver as imaginary part, 0 as real part
Usage example(s):
3i -> (0+3i)
(1+1i) -> (1+1i)
|
Usage example(s):
Modified (format): / 22-09-2017 / 09:53:27 / cg
|
-
i: aNumber
-
Form a complex number with
receiver as realPart
aNumber as imaginaryPart
this is the same as (self + aNumber i) but a little bit more efficient.
Usage example(s):
3i -> (0+3i)
(1+1i) -> (1+1i)
0 i:2 -> (0+2i)
(1 i:2) -> (1+2i)
|
comparing
-
closeFrom: aNumber
-
are these two numbers close?
Notice, that this is definitely not the best way to compensate
for rounding errors - see isAlmostEqualTo:aNumber nEpsilon:nE
(or at least, use closeFrom:withEpsilon:,
where the epsilon is given as arg)
-
closeFrom: aNumber withEpsilon: eps
-
are these two numbers close?
That is, within the given epsilon.
Notice, that this is probably not the best way to compensate
for rounding errors - see isAlmostEqualTo:aNumber nEpsilon:nE
(although it is useful to determine if a measured value
is within its spec)
-
closeTo: num
-
are these two numbers close to each other?
Notice, that this is definitely not the best way to compensate
for rounding errors - see isAlmostEqualTo:aNumber nEpsilon:nE
(or at least, use closeFrom:withEpsilon:,
where the epsilon is given as arg)
Usage example(s):
1 closeTo:1.0000000001
1 closeTo:1.001
1 closeTo:1.001 withEpsilon:0.001
|
-
closeTo: num withEpsilon: eps
-
are these two numbers close to each other?
Notice, that this is probably not the best way to compensate
for rounding errors - see isAlmostEqualTo:aNumber nEpsilon:nE
(although it is useful to determine if a measured value
is within its spec)
Usage example(s):
1 closeTo:1.0000000001
1 closeTo:1.001
1 closeTo:1.001 withEpsilon:0.1
1 closeTo:1.201 withEpsilon:0.1
3.14 closeTo:(3.14 asFixedPoint:2)
(3.14 asFixedPoint:2) closeTo:3.14
|
-
epsilonForCloseTo
-
return the epsilon used in the closeTo: comparison.
Here, we return the receiver's magnitude divided by 10000
Usage example(s):
1.0 epsilonForCloseTo
10 asShortFloat epsilonForCloseTo
10000 asShortFloat epsilonForCloseTo
|
-
isAlmostEqualTo: aNumber
-
return true, if the receiver, is inside the interval
aNumber-epsilon(aNumber) .. aNumber+epsilon(aNumber).
Err should be a fraction of 0..1.
Usage example(s):
Float pi isAlmostEqualTo:3.14159 -> false
Float pi isAlmostEqualTo:3.141592653589792 -> false
Float pi isAlmostEqualTo:3.141592653589793 -> true
Float pi isAlmostEqualTo:3.141592653589794 -> true
Float pi isAlmostEqualTo:3.141592653589795 -> false
Float pi isAlmostEqualTo:3.141592653589799 -> false
LongFloat pi isAlmostEqualTo:3.141592653589793q -> false
LongFloat pi isAlmostEqualTo:3.141592653589793239q -> true
(-1/2) isAlmostEqualTo:(-1/2) -> true
|
-
isAlmostEqualTo: aNumber nEpsilon: nE
-
return true, if the argument, aNumber represents almost the same numeric value
as the receiver, false otherwise.
nE is the number of minimal float distances, that the numbers may differ and
still be considered equal.
See documentation in LimitedPrecisionReal for more detail.
For background information why floats need this
read: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
-
isAlmostEqualTo: aNumber withError: errFraction
-
return true, if the receiver, is inside the interval
aNumber-err .. aNumber+err
where err is a fraction of aNumber.
Err should be a fraction of 0..1.
Usage example(s):
within 50%?
15 isAlmostEqualTo:10 withError:0.5 -> true i.e. (10 ± 50%)
5 isAlmostEqualTo:10 withError:0.5 -> true i.e. (10 ± 50%)
20 isAlmostEqualTo:10 withError:1 -> true i.e. (10 ± 100%)
0 isAlmostEqualTo:10 withError:1 -> true i.e. (10 ± 100%)
within 10%?
10.5 isAlmostEqualTo:10 withError:0.1 -> true i.e. (10 ± 10%)
within 1%
10.5 isAlmostEqualTo:10 withError:0.01 -> false i.e. (10 ± 1%)
10.3 isAlmostEqualTo:10 withError:0.01 -> false i.e. (10 ± 1%)
10.2 isAlmostEqualTo:10 withError:0.01 -> false i.e. (10 ± 1%)
10.1 isAlmostEqualTo:10 withError:0.01 -> true i.e. (10 ± 1%)
10.05 isAlmostEqualTo:10 withError:0.01 -> true i.e. (10 ± 1%)
9.9 isAlmostEqualTo:10 withError:0.01 -> true i.e. (10 ± 1%)
9.8 isAlmostEqualTo:10 withError:0.01 -> false i.e. (10 ± 1%)
within 0.1%
10.5 isAlmostEqualTo:10 withError:0.001 -> false i.e. (10 ± 0.1%)
10.07 isAlmostEqualTo:10 withError:0.001 -> false i.e. (10 ± 0.1%)
10.06 isAlmostEqualTo:10 withError:0.001 -> false i.e. (10 ± 0.1%)
10.05 isAlmostEqualTo:10 withError:0.001 -> false i.e. (10 ± 0.1%)
10.04 isAlmostEqualTo:10 withError:0.001 -> false i.e. (10 ± 0.1%)
10.03 isAlmostEqualTo:10 withError:0.001 -> false i.e. (10 ± 0.1%)
10.02 isAlmostEqualTo:10 withError:0.001 -> false i.e. (10 ± 0.1%)
10.01 isAlmostEqualTo:10 withError:0.001 -> true i.e. (10 ± 0.1%)
10.005 isAlmostEqualTo:10 withError:0.001 -> true i.e. (10 ± 0.1%)
9.99 isAlmostEqualTo:10 withError:0.001 -> true i.e. (10 ± 0.1%)
9.98 isAlmostEqualTo:10 withError:0.001 -> false i.e. (10 ± 0.1%)
within 0.1%
Float pi isAlmostEqualTo:3.14159 withError:1e-5 -> true
Float pi isAlmostEqualTo:3.14159 withError:1e-6 -> true
Float pi isAlmostEqualTo:3.14159 withError:1e-7 -> false
Float pi isAlmostEqualTo:3.141592653589793 withError:(Float pi epsilon) -> true
|
-
isEqual: aNumber within: accuracy
-
return true, if the distance between the receiver
and aNumber is <= accuracy.
Here accuracy is an absolute value
-
lexicographicalLessThan: aNumber
-
redefined for complex numbers
constants
-
halfPi
-
return Pi/2 in my representation (and accuracy).
-
halfPiNegative
-
return -Pi/2 in my representation (and accuracy).
-
halfpi
-
obsolete name for backward compatibility
return Pi/2 in my representation (and accuracy).
-
halfpiNegative
-
obsolete name for backward compatibility
return -Pi/2 in my representation (and accuracy).
-
pi
-
return Pi in my representation (and accuracy).
converting
-
+-% errorPercentage
-
return a MeasurementValue with a given relative error (percentage).
Usage example(s):
-
+/- anAbsoluteError
-
return a MeasurementValue with a given absolute error.
Usage example(s):
(100 +/- 5) * 2
(100 +/- 5) * (100 +/- 10)
(100 +/- 5) + (100 +/- 10)
(100 +/- 5) - (100 +/- 10)
|
-
@ aNumber
-
return a Point with the receiver as x-coordinate and the argument
as y-coordinate
-
asComplex
-
Return a complex number with the receiver as the real part and
zero as the imaginary part
-
asFixedDecimal: scale
( an extension from the stx:libbasic2 package )
-
return a fixedDecimal approximating the receiver's value
to scale fractional digits
Usage example(s):
(1/3) asFixedDecimal:2 0.33
(2/3) asFixedDecimal:2 0.67
(1/3) asFixedDecimal:5 0.33333
(2/3) asFixedDecimal:5 0.66667
|
-
asFloatChecked
-
Convert to a IEEE 754 double precision floating point.
Raises an error if the result cannot be represented as a float or is non-finite.
If the error is proceeded, you'll get a NaN or Inf
Usage example(s):
1000 factorial asLargeFloat asFloat -> inf
1000 factorial asLargeFloat asFloatChecked -> error
DomainError ignoreIn:[ 1000 factorial asLargeFloat asFloatChecked ] -> inf
1q1000 asFloat -> inf
1q1000 asFloatChecked -> error
DomainError ignoreIn:[ 1q1000 asFloatChecked ] -> inf
(1q / 1q1000) asFloat -> 0.0
(1q / 1q1000) asFloatChecked
DomainError ignoreIn:[ (1q / 1q1000) asFloatChecked ] -> 0.0
|
-
asIntegerChecked
-
return an integer with same value - might truncate.
Raises an error for non-finite numbers (NaN or INF).
If the error is proceeded, you'll get a NaN or Inf
-
asLargeFloatDecimalPrecision: numDigits
-
Convert to a large float with numDigits precision.
Usage example(s):
10000 factorial asLargeFloatDecimalPrecision:100
|
-
asLargeFloatPrecision: numBits
-
Convert to a large float with numBits precision.
** This method must be redefined in concrete classes (subclassResponsibility) **
-
asLongFloatChecked
-
Convert to a IEEE 754 extended precision floating point.
Raises an error if the result cannot be represented as a long float or is non-finite.
If the error is proceeded, you'll get a NaN or Inf.
Usage example(s):
10000 factorial asLargeFloat asLongFloat -> inf
10000 factorial asLargeFloat asLongFloatChecked -> error
|
-
asMetaNumber
-
by mapping all onto someNumber, we can doubleDispatch
Usage example(s):
Float NaN asMetaNumber
Float infinity asMetaNumber
Float negativeInfinity asMetaNumber
|
-
asNumber
-
I am a number, so return myself
-
asOctaFloatChecked
( an extension from the stx:libbasic2 package )
-
Convert to a IEEE 754 octuple precision floating point.
Raises an error if the result cannot be represented as a quad float.
Usage example(s):
1000 factorial asFloat -> INF
10000 factorial asFloat -> INF
10000 factorial negated asFloat -> -INF
1000 factorial asQuadFloat -> 4.023872601e2567
10000 factorial asQuadFloat -> inf
10000 factorial negated asQuadFloat -> -inf
10000 factorial asOctaFloat -> 2.84625968092e35659
1000 factorial asFloatChecked -> error
10000 factorial asQuadFloatChecked -> error
10000 factorial asOctaFloatChecked -> error
1000 factorial asLargeFloat asFloatChecked -> inf
1q1000 asFloatChecked -> inf
|
-
asPercentFrom: fullAmount
-
what is the percentage
taking the receiver's value from the argument.
i.e. how many percent of aHundredPercentValue is the receiver
Usage example(s):
(20 asPercentFrom:100) = 20
(20 asPercentFrom:200) = 10
(120 asPercentFrom:100) = 120
(5 asPercentFrom:1000) = 0.5
(5 asPercentFrom:10) = 50
(10 asPercentFrom:156) asFixedPoint:2
(15.6 asPercentFrom:156) asFixedPoint:2
|
-
asPoint
-
return a new Point with the receiver as all coordinates;
often used to supply the same value in two dimensions, as with
symmetrical gridding or scaling.
-
asQDoubleChecked
( an extension from the stx:libbasic2 package )
-
Convert to a QDouble.
Raises an error if the result cannot be represented as such.
Usage example(s):
1000 factorial asLargeFloat asQDouble -> inf
1000 factorial asLargeFloat asQDoubleChecked -> error
1q1000 asQDouble -> 1E+1000
1q1000 asQDoubleChecked -> error
|
-
asQuadFloatChecked
( an extension from the stx:libbasic2 package )
-
Convert to a IEEE 754 quadruple precision floating point.
Raises an error if the result cannot be represented as a quad float.
Usage example(s):
1000 factorial asFloat -> INF
10000 factorial asFloat -> INF
10000 factorial negated asFloat -> -INF
1000 factorial asQuadFloat -> 4.023872601e2567
10000 factorial asQuadFloat -> inf
10000 factorial negated asQuadFloat -> -inf
10000 factorial asOctaFloat -> 2.84625968092e35659
1000 factorial asFloatChecked -> error
10000 factorial asQuadFloatChecked -> error
10000 factorial asOctaFloatChecked -> error
1000 factorial asLargeFloat asFloatChecked -> inf
1q1000 asFloatChecked -> inf
|
-
asShortFloatChecked
-
Convert to a IEEE 754 single precision floating point.
Raises an error if the result cannot be represented as a short float or is non-finite.
If the error is proceeded, you'll get a NaN or Inf.
Usage example(s):
1000 factorial asShortFloat -> inf
1000 factorial asShortFloatChecked -> error
1q1000 asShortFloatChecked -> error
-1q1000 asShortFloatChecked -> error
|
-
asTimeDuration
-
return an TimeDuration object from the receiver,
taking the receiver as number of seconds
Usage example(s):
5 asTimeDuration
50.25 asTimeDuration
3600 asTimeDuration
'5m' asTimeDuration
|
-
asTruncatedMilliseconds
-
compatibility with TimeDuration.
Convert a number representing seconds to milliseconds.
Values smaller than 1 ms (0.001) will be returned as 0.
Usage example(s):
5 asTruncatedMilliseconds => 5000
50.25 asTruncatedMilliseconds => 50250
(3/4) asTruncatedMilliseconds => 750
0.0025 asTruncatedMilliseconds => 2
0.0015 asTruncatedMilliseconds => 1
0.0007 asTruncatedMilliseconds => 0
|
-
degreesToRadians
-
interpreting the receiver as degrees, return the radians
Usage example(s):
180 degreesToRadians
Float pi radiansToDegrees
180 asLongFloat degreesToRadians
180 asQuadFloat degreesToRadians
180 asLargeFloat degreesToRadians
|
-
literalArrayEncoding
-
encode myself as an array literal, from which a copy of the receiver
can be reconstructed with #decodeAsLiteralArray.
-
percentOf: hundredPercent
-
how many is self-percent from the argument
Usage example(s):
20 percentOf:100 => 20
20 percentOf:6 => (6/5)
(20 percentOf:6) asFixedPoint:2 => 1.20
(10 percentOf:156) asFixedPoint:2 => 15.60
(105 percentOf:156) asFixedPoint:2 => 163.80
|
-
radiansToDegrees
-
interpreting the receiver as radians, return the degrees
Usage example(s):
180 degreesToRadians radiansToDegrees
180 asLongFloat degreesToRadians radiansToDegrees
180 asLargeFloat degreesToRadians radiansToDegrees
LongFloat pi radiansToDegrees
LargeFloat pi radiansToDegrees
|
-
withScale: newScale
-
return a fixedPoint number representing the same value as the receiver,
with newScale number of post-decimal digits
Usage example(s):
1234 withScale:2
1234.1 withScale:2
1234.12 withScale:2
1234.123 withScale:2
(1/7) withScale:2
|
-
± anError
-
return a MeasurementValue with a given absolute error.
Same as +/-
Usage example(s):
(100 ± 5) * 2 -> (200 ± 10)
(100 ± 5) * (100 +/- 10) -> (MeasurementValue value:10000 minValue:(8550) maxValue:(11550))
(100 ± 5) + (100 +/- 10) -> (200 ± 15)
(100 ± 5) - (100 +/- 10) -> (0 ± 15)
(100 ± 5) ± 10 -> (100 ± 15)
|
-
±% anErrorPercentage
-
return a MeasurementValue with a given relative error (percentage).
Same as +-%
Usage example(s):
(100 ±% 5) -> (100 ± 5)
(50 ±% 5.0) -> (50 ± 2.5)
(50 ±% 10) * 2 -> (100 ± 10)
(100 ±% 5) + (100 ±% 10) -> (200 ± 15)
(100 ±% 5) - (100 ±% 10) -> (0 ± 15)
(100 ±% 5) * (100 ±% 10) -> (MeasurementValue value:10000 minValue:8550 maxValue:11550)
(100 ±% 5) ± 10 -> (100 ± 15)
(100 ±% 10) ±% 10 ->
|
converting-times
-
days
-
return a TimeDuration representing this number of days
Usage example(s):
1000 milliseconds
10 seconds
10 minutes
1 days
|
-
hours
-
return a TimeDuration representing this number of hours
-
microseconds
-
return a TimeDuration representing this number of microseconds.
Usage example(s):
-
milliSeconds
-
marked as obsolete by Stefan Vogel at 25-Apr-2024
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
milliseconds
-
return a TimeDuration representing this number of milliseconds.
Same as milliSeconds, for dialect compatibility
Usage example(s):
-
minutes
-
return a TimeDuration representing this number of minutes
Usage example(s):
1000 milliseconds
10 seconds
10 minutes
|
-
nanoseconds
-
return a TimeDuration representing this number of nanoseconds.
Usage example(s):
40.5 nanoseconds asPicoseconds
(40.5 nanoseconds / 2) asPicoseconds
40 nanoseconds
40 nanoseconds asPicoseconds
44 milliseconds asMicroseconds
44 milliseconds
|
-
picoseconds
-
return a TimeDuration representing this number of picoseconds.
Usage example(s):
-
seconds
-
return a TimeDuration representing this number of seconds
Usage example(s):
1000 milliseconds
10 seconds
10 minutes
|
-
weeks
-
return a TimeDuration representing this number of weeks
Usage example(s):
1000 milliseconds
10 seconds
10 minutes
1 days
1 weeks
|
-
years
-
return a TimeDuration representing this number of years
Usage example(s):
1000 milliseconds
10 seconds
10 minutes
1 days
1 years
|
copying
-
deepCopyUsing: aDictionary postCopySelector: postCopySelector
-
return a deep copy of myself
- reimplemented here since numbers are immutable
double dispatching
-
differenceFromMeasurementValue: aMeasurementValue
-
return the difference of aMeasurementValue and the receiver.
Care for the error to propagate into the result.
-
differenceFromPoint: aPoint
-
return the difference from aPoint - self
-
differenceFromTimestamp: aTimestamp
-
I am to be interpreted as seconds, return the timestamp this number of seconds
before aTimestamp
Usage example(s):
100.0 differenceFromTimestamp:Timestamp now
|t1 t2|
t1 := Timestamp now.
t2 := 1.5 differenceFromTimestamp:t1.
t1 inspect. t2 inspect.
|
-
productFromMatrix: aMatrix
( an extension from the stx:libbasic2 package )
-
Answer the result of multiplying 'aMatrix' by the receiver.
-
productFromMeasurementValue: aMeasurementValue
-
return the product of aMeasurementValue and the receiver.
Care for the error to propagate into the result.
-
productFromPoint: aPoint
-
return the product of aPoint * self
-
quotientFromMatrix: aMatrix
( an extension from the stx:libbasic2 package )
-
Answer the result of dividing 'aMatrix' by the receiver.
-
quotientFromMeasurementValue: aMeasurementValue
-
return the quotient of aMeasurementValue and the receiver.
Care for the error to propagate into the result.
-
quotientFromPoint: aPoint
-
return the quotient of aPoint / self
-
sumFromMeasurementValue: aMeasurementValue
-
return the sum of aMeasurementValue and the receiver.
Care for the error to propagate into the result.
-
sumFromPoint: aPoint
-
return the sum of aPoint + self
-
sumFromTimestamp: aTimestamp
-
I am to be interpreted as seconds, return the timestamp this number of seconds
after aTimestamp
Usage example(s):
Timestamp now + 3600
Timestamp now sumFromTimestamp:aTimestamp
100.0 sumFromTimestamp:Timestamp now
|t1 t2|
t1 := Timestamp now.
t2 := 1.5 sumFromTimestamp:t1.
t1 inspect. t2 inspect.
|
inspecting
-
inspectorValueListIconFor: anInspector
( an extension from the stx:libtool package )
-
returns the icon to be shown alongside the value list of an inspector
-
inspectorValueStringInListFor: anInspector
-
returns a string to be shown in the inspector's list
intervals
-
downTo: stop
-
return an interval from receiver down to the argument, incrementing by -1
Usage example(s):
(10 downTo:1) do:[:i | Transcript showCR:i].
|
-
downTo: stop by: step
-
return an interval from receiver down to the argument, decrementing by step
Usage example(s):
(10 downTo:1 by:0.5) do:[:i | Transcript showCR:i].
|
-
to: stop
-
return an interval from receiver up to the argument, incrementing by 1
-
to: stop by: step
-
return an interval from receiver up to the argument, incrementing by step
-
to: stop byFactor: factor
-
return a geometric series from receiver up to the argument;
elements have a constant factor in between
Usage example(s):
(1 to:256 byFactor:2)
(256 to:1 byFactor:1/2)
|
iteration
-
timesRepeat: aBlock
-
evaluate the argument, aBlock self times
-
timesRepeatWithExit: aOneArgBlock
-
evaluate the argument, aBlock self times;
pass an exit block to the one-arg-block
Usage example(s):
10 timesRepeatWithExit:[:exit |
Transcript showCR:'iteration'.
(Random nextBetween:1 and:10) > 7 ifTrue:[exit value].
].
|
mathematical functions
-
agm: y
-
return the arithmetic-geometric mean agm(x, y) of the receiver (x) and the argument, y.
See https://en.wikipedia.org/wiki/Arithmetic-geometric_mean
and http://www.wolframalpha.com/input/?i=agm(24,+6)
-
angle
-
Return the radian angle for this treated as a Complex number w.o. imaginary part.
-
cbrt
-
return the cubic root of the receiver
-
conjugated
-
Return the complex conjugate of this Number.
-
erf
-
error function; see eg. wikipedia
-
exp
-
compute e**x of the receiver
-
fibPhi
-
3 fib
3.0 fibPhi
100 fib
100.0 fibPhi
-
floorLog: radix
-
return the logarithm truncated as an integer.
Similar to (and for radix 10 and positive log the same) as integerLog10
-
imaginary
-
Return the imaginary part of a complex number.
For non-complex numbers, zero is returned.
-
integerLog10
-
return the truncation of log10 of the receiver.
The same as (self log:10) floor (for positive logs).
Used eg. to find out the number of digits needed
to print a number/and for conversion to a LargeInteger.
Usage example(s):
(10 raisedTo:100) log10 100.0
(10 raisedTo:100) integerLog10 100
(10 raisedTo:100) asFloat integerLog10 100
(10 raisedTo:1000) log10 1000.0
(10 raisedTo:1000) integerLog10 1000
(10 raisedTo:1000) asFloat integerLog10 INF error (float overflow)
Number trapInfinity:[ 0.0 integerLog10 ] -> -INF
Number trapImaginary:[ -1.0 integerLog10 ] -> (0+1i)
|
-
integerLog2
-
return the truncation of log2 of the receiver.
The same as (self log:2) floor (for positive logs).
Used eg. to find out the number of digits needed
to print a number/and for conversion to a LargeInteger.
Usage example(s):
(10 raisedTo:100) log2 332.192809488736
(10 raisedTo:100) integerLog2 332
(10 raisedTo:100) asFloat integerLog2 332
(10 raisedTo:1000) log2 3321.92809488736
(10 raisedTo:1000) integerLog2 3321
(10 raisedTo:1000) asFloat integerLog2 INF error (float overflow)
|
-
integerSqrt
-
return the largest integer which is less or equal to the receiver's square root.
Usage example(s):
-
ldexp: exp
-
multiply the receiver by an integral power of 2.
I.e. return self * (2 ^ exp).
This is also the operation to reconstruct the original float from its
mantissa and exponent: (f mantissa ldexp:f exponent) = f
Usage example(s):
1.0 ldexp:16 -> 65536.0
1.0 ldexp:100 -> 1.26765060022823E+30
1 * (2 raisedToInteger:100) -> 1267650600228229401496703205376
1 ldexp:200 -> 1606938044258990275541962092341162602522202993782792835301376
1.0 ldexp:200 -> 1.60693804425899E+60
|
-
ln
-
return the natural logarithm of myself.
Raises an exception, if the receiver is less or equal to zero.
Usage example(s):
(10 raisedTo:1000) ln 2302.58509299405
(10 raisedTo:1000) asFloat ln error - cannot represent (10 raisedTo:1000)
(10 raisedTo:1000) asIEEEFloat ln error - cannot represent (10 raisedTo:1000)
(10 raisedTo:1000) asQDouble ln error - cannot represent (10 raisedTo:1000)
(10 raisedTo:1000) asLongFloat ln 2302.585092994045684
(10 raisedTo:1000) asLargeFloat ln 2302.585092994045
|
-
log
-
return log base 10 of the receiver.
Alias for log:10.
-
log10
-
return the base-10 logarithm of the receiver.
Raises an exception, if the receiver is less or equal to zero.
Here, fallback to the general logarithm code.
Usage example(s):
(10 raisedTo:1000) log10
(10 raisedTo:2000) log10
(10 raisedTo:4000) log10
(10 raisedTo:8000) log10
3 log10 -> 0.477121254719662
-3 log10 -> error
3.0 log10 -> 0.477121254719662
-3.0 log10 -> error
Number trapImaginary:[ -3 log10 ] -> (0.477121254719662+1.36437635384184i)
Number trapInfinity:[ 0 log10 ] -> -inf
10.0 log10 -> 1.0
10.0 asIEEEFloat log10 -> 1.0
10.0 asShortFloat log10 -> 1.0
(10.0 asIEEEFloat:32) log10 -> 1.00000001388676
10.0 asLongFloat log10 -> 1.0
10.0 asQuadFloat log10 -> 0.999999999999997157829057521890382
10.0 asOctaFloat log10 -> 1.0
10.0 asQDouble log10 -> 1.0
10.0 asLargeFloat log10 -> 1.00000000000001731947918415244203060865402221679687500
(10.0 asLargeFloatPrecision:200) log10 -> 1.0000000000000000000000000000000000000000000000000000000000012446030556
0.1 ln -2.30258509299405
0.1 asShortFloat ln -2.302585
0.1 asLongFloat ln -2.302585092994045629
0.1 asQuadFloat ln -2.30258509299403613113099847804875
0.1 asOctaFloat ln -2.30258509299404562850684022342653872716347359387638277683520000207135
0.1 asQDouble ln -2.3025850929940456285068402234265387271634735938764
0.1 asLargeFloat ln -2.30258509299404545700440394284669309854507446289062500
1.0 ln 0.0
1.0 asShortFloat ln 0.0
1.0 asLongFloat ln 0.0
1.0 asQuadFloat ln 1.05703092019725275463315554170128e-14
1.0 asOctaFloat ln 1.901692606553609597176915051086436273943331551609219019812349126886455e-70
1.0 asQDouble ln 0.0
1.0 asLargeFloat ln 0.00000000000004243371000881944264563316903763309556521
1.0 asLargeFloat log10 -> 1.0
1.1 ln 0.0953101798043249
1.1 asShortFloat ln 0.0953102
1.1 asLongFloat ln 0.09531017980432494079
1.1 asQuadFloat ln 0.0953101798043328539871388774360559
1.1 asOctaFloat ln 0.09531017980432494078744482329214659054710180079077044654582965101805817
1.1 asQDouble ln 0.09531017980432494078744482329214659054710180079077
1.1 asLargeFloat ln 0.09531017980440484316240201678738230839371681213378906
1.1 log10 0.0413926851582251
1.1 asShortFloat log10 0.0413927
1.1 asLongFloat log10 0.04139268515822507582
1.1 asQuadFloat log10 0.0413926851582284376002860264816636
1.1 asOctaFloat log10 0.04139268515822507581665330045346321583627669892912363955022882609620284
1.1 asQDouble log10 0.041392685158225075816653300453463215836276698929124
1.1 asLargeFloat log10 0.04139268515825977878819230681983754038810729980468750
|
-
log2
-
return log base-2 of the receiver.
Raises an exception, if the receiver is less or equal to zero.
Here, fallback to the general logarithm code.
Usage example(s):
2.0 log2
4.0 log2
(2.0 raisedTo:100.0) log2
(10 raisedTo:1000) log2
(10 raisedTo:2000) log2
(10 raisedTo:4000) log2
(10 raisedTo:8000) log2
Float infinity log2
Float NaN log2
|
-
log: aNumber
-
return log base aNumber of the receiver.
This will usually return a float value
Usage example(s):
1000 log:10
9 log:3
(1000 log:10) floor
(10 raisedTo:1000) log:10
|
-
nthRoot: nIn
-
return the nth root of the receiver
Usage example(s):
10 nthRoot:1 -> 10
10 nthRoot:2 -> 3.16227766016838
10 nthRoot:3 -> 2.154434690031883722
10 nthRoot:4 -> 1.77827941003892
10 nthRoot:5 -> 1.58489319246111
10 nthRoot:17 -> 1.14504756993828
(10 nthRoot:4) raisedTo:4
(10 nthRoot:17) raisedTo:17
(100.0 nthRoot:1) raisedTo:1
(100.0 nthRoot:4) raisedTo:4
(100.0 nthRoot:5) raisedTo:5
(100.0 nthRoot:6) raisedTo:6 => 100.0
(100.0 nthRoot:27) raisedTo:27 => 99.9999999999999 (errors accumulate)
(100.0 asLargeFloat nthRoot:27) raisedTo:27 => 100.0
16.0 nthRoot:2 -> 4.0
-16.0 nthRoot:3 -> -2.51984209978975
16.0 nthRoot:4 -> 2.0
-16.0 nthRoot:5 -> -1.74110112659225
-16.0 nthRoot:2 -> error
-16.0 nthRoot:4 -> error
(Complex trapImaginary:[-16.0 nthRoot:4])
(Complex trapImaginary:[-16.0 nthRoot:4]) raisedTo:4 -> -16 (with some rounding errors)
Float infinity nthRoot:4
Float NaN nthRoot:4
|
-
raisedTo: aNumber
-
return the receiver raised to aNumber
Usage example(s):
2 raisedTo: 4
-2 raisedTo: 4
4 raisedTo: 1/2
-4 raisedTo: 1/2
8 raisedTo: 1/3
-8 raisedTo: 1/3
10 raisedTo: 4
10 raisedTo: -4
10 asQDouble raisedTo: 4
10 asQDouble raisedTo: -4
2.0 asQuadFloat raisedTo:(2.0 asQuadFloat)
2.0 asQuadFloat raisedTo:(0.5 asQuadFloat)
2.0 asQDouble raisedTo:(0.5)
2.0 asQDouble raisedTo:(0.5 asQDouble)
2.0 asQDouble raisedTo:(0.5 asQuadFloat)
-8 asQDouble raisedTo:(1/3)
-8 asQuadFloat raisedTo:(1/3)
-8 asLargeFloat raisedTo:(1/3)
-8 asFloat raisedTo:(1/3)
-8 asShortFloat raisedTo:(1/3)
|
-
real
-
Return the real part of a complex number.
For non-complex numbers, the receiver is returned.
-
sqrt
-
return the square root of the receiver
-
timesTenPower: anInteger
-
Return the receiver multiplied by 10 raised to the power of the argument.
i.e. self * (10 ** anInteger)
Usage example(s):
123 timesTenPower:0 = 123*1 -> 123
123 timesTenPower:1 = 123*10 -> 1230
123 timesTenPower:2 = 123*100 -> 12300
123 timesTenPower:3 = 123*1000 -> 123000
(2 timesTenPower: -150) timesTenPower: 150 -> 2
(2 timesTenPower: 150) timesTenPower: -150 -> 2
(2 timesTenPower: 150) timesTenPower: -149 -> 20
|
-
timesTwoPower: anInteger
-
Return the receiver multiplied by 2 raised to the power of the argument.
I.e. self * (2**n)
Warning: may return infinity, if the result is too big;
or zero if too small.
For protocol completeness wrt. Squeak and ST80.
Usage example(s):
2 timesTwoPower:0 = 2*1 -> 2
2 timesTwoPower:1 = 2*2 -> 4
2 timesTwoPower:2 = 2*4 -> 8
123 timesTwoPower:0 = 123*1 -> 123
123 timesTwoPower:1 = 123*2 -> 246
123 timesTwoPower:2 = 123*4 -> 492
123 timesTwoPower:3 = 123*8 -> 984
(2 timesTwoPower: -150) timesTwoPower: 150 -> 2
(2 timesTwoPower: 150) timesTwoPower: -150 -> 2
(2 timesTwoPower: 150) timesTwoPower: -149 -> 4
|
measurement values
-
maxValue
-
the maximum possible value taking me as a measurement with possible error;
as I am exact, that's myself
-
minValue
-
the minimum possible value taking me as a measurement with possible error;
as I am exact, that's myself
printing & storing
-
displayOn: aGCOrStream
-
return a string to display the receiver.
The output radix is usually 10, but can be changed by setting
DefaultDisplayRadix (see Integer>>displayRadix:)
-
printOn: aStream
-
append a printed description of the receiver to aStream
-
printOn: aStream base: b
-
return a string representation of the receiver in the specified
radix (without the initial XXr)
Usage example(s):
10 printOn:Transcript base:3
31 printOn:Transcript base:3
-20 printOn:Transcript base:16
-20 printOn:Transcript base:10
3000 factorial printOn:Transcript base:10
|
-
printOn: aStream base: b showRadix: showRadix
-
the central print method for integer.
Must be defined in concrete classes
** This method must be redefined in concrete classes (subclassResponsibility) **
-
printOn: aStream paddedWith: padCharacter to: size base: radix
-
100 printOn:Transcript paddedWith:$0 to:10 base:10. Transcript cr.
100 printOn:Transcript paddedWith:$0 to:10 base:16. Transcript cr.
100 printOn:Transcript paddedWith:(Character space) to:10 base:16. Transcript cr.
100 printOn:Transcript paddedWith:(Character space) to:10 base:2. Transcript cr.
-
printOn: aStream thousandsSeparator: thousandsSeparator
-
print the receiver as business number with thousands separator to aStream.
thousandsSeparator is locale specific and is usualy a single quote ('), a comma or period.
Usage example(s):
swiss style:
1000000 printOn:Transcript thousandsSeparator:$'. Transcript cr.
12345678 printOn:Transcript thousandsSeparator:$'. Transcript cr.
1234567 printOn:Transcript thousandsSeparator:$'. Transcript cr.
123456 printOn:Transcript thousandsSeparator:$'. Transcript cr.
123056 printOn:Transcript thousandsSeparator:$'. Transcript cr.
12345 printOn:Transcript thousandsSeparator:$'. Transcript cr.
1234 printOn:Transcript thousandsSeparator:$'. Transcript cr.
123 printOn:Transcript thousandsSeparator:$'. Transcript cr.
(12345678.12 asFixedPoint:2) printOn:Transcript thousandsSeparator:$'. Transcript cr.
1234567.12 printOn:Transcript thousandsSeparator:$'. Transcript cr.
123456.12 printOn:Transcript thousandsSeparator:$'. Transcript cr.
123056.12 printOn:Transcript thousandsSeparator:$'. Transcript cr.
12345.12 printOn:Transcript thousandsSeparator:$'. Transcript cr.
1234.12 printOn:Transcript thousandsSeparator:$'. Transcript cr.
123.12 printOn:Transcript thousandsSeparator:$'. Transcript cr.
us style:
1000000 printOn:Transcript thousandsSeparator:$,. Transcript cr.
12345678 printOn:Transcript thousandsSeparator:$,. Transcript cr.
1234567 printOn:Transcript thousandsSeparator:$,. Transcript cr.
123456 printOn:Transcript thousandsSeparator:$,. Transcript cr.
12345 printOn:Transcript thousandsSeparator:$,. Transcript cr.
1234 printOn:Transcript thousandsSeparator:$,. Transcript cr.
123 printOn:Transcript thousandsSeparator:$,. Transcript cr.
german (european ?) style
1000000 printOn:Transcript thousandsSeparator:$.. Transcript cr.
12345678 printOn:Transcript thousandsSeparator:$.. Transcript cr.
1234567 printOn:Transcript thousandsSeparator:$.. Transcript cr.
123456 printOn:Transcript thousandsSeparator:$.. Transcript cr.
12345 printOn:Transcript thousandsSeparator:$.. Transcript cr.
1234 printOn:Transcript thousandsSeparator:$.. Transcript cr.
123 printOn:Transcript thousandsSeparator:$.. Transcript cr.
|
-
printStringBase: base
-
-
printStringBase: base showRadix: showRadixBoolean
-
return a string representation of the receiver in the specified base;
optionally prepend XXr to the string.
See also: radixPrintStringRadix:
printOn:base:showRadix:
-
printStringFormat: formatString
-
Return a printed representation of the receiver as specified by formatString,
which is defined by PrintfScanf.
Usage example(s):
1.2345 printStringFormat:'%4.2f' -> '1.23'
123 printStringFormat:'%4d' -> ' 123'
123 printStringFormat:'%5.2f' -> '123.0'
|
-
printStringRadix: base
-
marked as obsolete by Stefan Vogel at 22-Apr-2024
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
printStringRadix: base showRadix: showRadixBoolean
-
marked as obsolete by Stefan Vogel at 22-Apr-2024
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
printStringScientific
-
return a 'user friendly' scientific printString.
Notice: this returns a Text object with superscript digits,
which requires a font capapble of displaying it correctly.
Also: the returned string is not meant to be read back - purely for GUIs
Usage example(s):
1.23456 printString -> '1.23456'
1.23456 printStringScientific 1.23456×10^0 (with superscript zero at end)
1.23e14 printStringScientific 1.23×10^14 (with superscript zero at end)
PrintfScanf printf:'%e' argument:1.23456 -> '1.23456e0'
PrintfScanf printf:'%g' argument:1.23456 -> '1.23456'
PrintfScanf printf:'%f' argument:1.23456 -> '1.23456'
PrintfScanf printf:'%e' argument:1.234 -> '1.234e0'
PrintfScanf printf:'%g' argument:1.234 -> '1.234'
PrintfScanf printf:'%f' argument:1.234 -> '1.234'
|
-
printStringWithThousandsSeparator
-
print the receiver as swiss business number with thousands separator to aStream.
Caveat: Should use the separator from the locale here
Usage example(s):
1000000 printStringWithThousandsSeparator
12345678 printStringWithThousandsSeparator
1234567 printStringWithThousandsSeparator
123456 printStringWithThousandsSeparator
12345 printStringWithThousandsSeparator
1234 printStringWithThousandsSeparator
123 printStringWithThousandsSeparator
1000000 asFixedPoint printStringWithThousandsSeparator
12345678 asFixedPoint printStringWithThousandsSeparator
1234567 asFixedPoint printStringWithThousandsSeparator
123456 asFixedPoint printStringWithThousandsSeparator
12345 asFixedPoint printStringWithThousandsSeparator
1234 asFixedPoint printStringWithThousandsSeparator
123 asFixedPoint printStringWithThousandsSeparator
((9999999//10000) asFixedPoint:9) printStringWithThousandsSeparator
((99999999//10000) asFixedPoint:9) printStringWithThousandsSeparator
|
-
printStringWithThousandsSeparator: thousandsSeparator
-
print the receiver as business number with a thousands separator to aStream.
Notice:
americans use comma
germans (europeans ?) use a dot
swiss people (business people ?) use a single quote
Caveat: Should use the separator from the locale here
Usage example(s):
Transcript showCR:(1000000 printStringWithThousandsSeparator:$').
Transcript showCR:(12345678 printStringWithThousandsSeparator:$').
Transcript showCR:(1234567 printStringWithThousandsSeparator:$').
Transcript showCR:(123456 printStringWithThousandsSeparator:$').
Transcript showCR:(12345 printStringWithThousandsSeparator:$').
Transcript showCR:(1234 printStringWithThousandsSeparator:$').
Transcript showCR:(123 printStringWithThousandsSeparator:$').
Transcript showCR:(1000000 printStringWithThousandsSeparator:$,).
Transcript showCR:(12345678 printStringWithThousandsSeparator:$,).
Transcript showCR:(1234567 printStringWithThousandsSeparator:$,).
Transcript showCR:(123456 printStringWithThousandsSeparator:$,).
Transcript showCR:(12345 printStringWithThousandsSeparator:$,).
Transcript showCR:(1234 printStringWithThousandsSeparator:$,).
Transcript showCR:(123 printStringWithThousandsSeparator:$,).
Transcript showCR:((1000000 asFixedPoint:2) printStringWithThousandsSeparator:$,).
Transcript showCR:((12345678 asFixedPoint:2) printStringWithThousandsSeparator:$,).
Transcript showCR:((1234567 asFixedPoint:2) printStringWithThousandsSeparator:$,).
Transcript showCR:((123456 asFixedPoint:2) printStringWithThousandsSeparator:$,).
Transcript showCR:((12345 asFixedPoint:2) printStringWithThousandsSeparator:$,).
Transcript showCR:((1234 asFixedPoint:2) printStringWithThousandsSeparator:$,).
Transcript showCR:((123 asFixedPoint:2) printStringWithThousandsSeparator:$,).
|
-
printWithSignOn: aStream
-
append a printed description of the receiver to aStream.
Prepends '+' or '-'
-
printWithoutFractionIfPossibleOn: aStream
-
append a printed representation of the receiver to
the argument, aStream.
If the receiver has no fractional part (i.e. ends with .0),
then print the integer part only
Usage example(s):
1.0 printOn:Transcript
1.0 printWithoutFractionIfPossibleOn:Transcript
1.1 printOn:Transcript
1.1 printWithoutFractionIfPossibleOn:Transcript
(1/10) printOn:Transcript
(1/10) printWithoutFractionIfPossibleOn:Transcript
(1/1000) printOn:Transcript
(1/1000) printWithoutFractionIfPossibleOn:Transcript
((1/1000) asScaledDecimal) printWithoutFractionIfPossibleOn:Transcript
1e10 printWithoutFractionIfPossibleOn:Transcript
1e15 printWithoutFractionIfPossibleOn:Transcript
1e20 printWithoutFractionIfPossibleOn:Transcript
|
-
printfPrintString: formatString
-
Return a printed representation of the receiver as specified by formatString,
which is defined by printf.
Usage example(s):
2.0 asQDouble printfPrintString:'%10f'
2.0 asQDouble printfPrintString:'%10.8f'
2.0 printfPrintString:'%10.8f'
12345 printfPrintString:'0x%06x'
|
-
radixPrintStringRadix: radix
-
return a string representation of the receiver in the specified
base; prepend XXr to the string
Usage example(s):
31 radixPrintStringRadix:2
31 radixPrintStringRadix:3
31 radixPrintStringRadix:10
31 radixPrintStringRadix:16
31 radixPrintStringRadix:36
|
-
storeOn: aStream
-
append a string for storing the receiver onto the argument, aStream
- since numbers are literals,they store as they print.
-
storeString
-
return a string for storing
- since numbers are literals, they store as they print.
testing
-
even
-
return true if the receiver is divisible by 2.
Usage example(s):
2 even
2.0 even
3.0 even
2.4 even
(5/3) even
2 asFraction even
(2 asFixedPoint:5) even
(2 asScaledDecimal:5) even
(2 asFixedDecimal:5) even
2 asFloatE even
2 asFloatD even
2 asFloatQ even
2 asFloatQD even
(2.1 asFloatQD - (QDouble readFrom:'2.1')) fractionPart
|
-
isDivisibleBy: aNumber
-
return true, if the receiver can be divided by the argument, aNumber without a remainder.
Notice, that the result is only worth trusting,
if the receiver is an integer.
Usage example(s):
3 isDivisibleBy:2 false
4 isDivisibleBy:2 true
4.0 isDivisibleBy:2 true
4.0 isDivisibleBy:2.0 true
4.1 isDivisibleBy:2.0 false
4.5 isDivisibleBy:4.5 true
4.5 isDivisibleBy:1.0 false
4.5 isDivisibleBy:1 false
|
-
isExact
-
Answer whether the receiver performs exact arithmetic.
To be redefined in concrete classes.
-
isNumber
-
return true, if the receiver is a kind of number
-
isPerfectSquare
-
return true if I am a perfect square.
That is a number for which the square root is an integer.
Usage example(s):
0 isPerfectSquare
0.0 isPerfectSquare
1 isPerfectSquare
1.0 isPerfectSquare
2 isPerfectSquare
2.0 isPerfectSquare
3 isPerfectSquare
3.0 isPerfectSquare
4 isPerfectSquare
4.0 isPerfectSquare
9 isPerfectSquare
9.0 isPerfectSquare
123456789012345678901234567890 squared isPerfectSquare
1000 factorial squared isPerfectSquare
(1 to:100) count:#isPerfectSquare
(1 to:1000) count:#isPerfectSquare
(1 to:1000) select:#isPerfectSquare
|
-
isReal
-
return true, if the receiver is some kind of real number (as opposed to a complex);
true is returned here - the method is redefined from Object.
-
isRealNumber
-
return true, if the receiver is a real number.
Notice that isReal is only understood inside the number hierarchy,
whereas isRealNumber is understood by everyone
-
isZero
-
return true, if the receiver is zero
Usage example(s):
0.0 isZero.
0.0 asLargeFloat isZero
|
tracing
-
traceInto: aRequestor level: level from: referrer
-
double dispatch into tracer, passing my type implicitely in the selector
trigonometric
-
arcCos
-
return the arccosine of the receiver (in radians)
-
arcCot
-
return the arccotangent of the receiver (as radians)
Usage example(s):
1 cot => 0.642092615934331
1 cot arcCot => 1.0
0.1 arcCot => 1.47112767430373
0.00001 arcCot => 1.5707863267949
0 arcCot => 1.5707963267949
0.00001 asFloat128 arcCot => 1.57078632679489695256383697443
0 asFloat128 arcCot => 1.57079632679489661923132169164
|
-
arcSin
-
return the arcsine of the receiver (in radians)
-
arcTan
-
return the arctangent of the receiver (as radians)
-
arcTan2: x
-
return atan2(self,x) (as radians).
Notice that the receiver is y
(as in the called C-library function of Float-arcTan2)
Usage example(s):
0 asQDouble arcTan2:0 -> error
1 asQDouble arcTan2:0 -> 1.5707963267949 (pi/2)
-1 asQDouble arcTan2:0 -> -1.5707963267949 (-pi/2)
0 asQDouble arcTan2:-1 -> 3.14159265358979 (pi)
0 asQDouble arcTan2:1 -> 0.0
1 asQDouble arcTan2:1 -> 0.785398163397448 (pi/4)
-1 asQDouble arcTan2:-1 -> -2.35619449019234 -(3/4 pi)
1 asQDouble arcTan2:-1 -> 2.35619449019234 (3/4 pi)
-1 asQDouble arcTan2:1 -> -0.785398163397448 -(pi/4)
2 asQDouble arcTan:1 -> 1.10714871779409
1 asQDouble arcTan:2 -> 0.463647609000806
|
Usage example(s):
0 asLargeFloat arcTan2:0 -> error
1 asLargeFloat arcTan2:0 -> 1.5707963267949 (pi/2)
-1 asLargeFloat arcTan2:0 -> -1.5707963267949 (-pi/2)
0 asLargeFloat arcTan2:-1 -> 3.14159265358979 (pi)
0 asLargeFloat arcTan2:1 -> 0.0
1 asLargeFloat arcTan2:1 -> 0.785398163397448 (pi/4)
-1 asLargeFloat arcTan2:-1 -> -2.35619449019234 -(3/4 pi)
1 asLargeFloat arcTan2:-1 -> 2.35619449019234 (3/4 pi)
-1 asLargeFloat arcTan2:1 -> -0.785398163397448 -(pi/4)
2 asLargeFloat arcTan:1 -> 1.10714871779409
1 asLargeFloat arcTan:2 -> 0.463647609000806
|
-
arcTan: denominator
-
Evaluate the four quadrant arc tangent of the argument denominator (x) and the receiver (y).
-
cos
-
return the cosine of the receiver (interpreted as radians)
-
cot
-
return the cotangent of the receiver
-
csc
-
return the cosecant of the receiver (interpreted as radians)
-
hypot: b
-
answer sqrt(self*self + b*b)
The value computed by this function is
- the length of the hypotenuse of a right-angled triangle with sides of length x and y,
- or the distance of the point (x,y) from the origin (0,0),
- or the magnitude of a complex number x+iy.
Usage example(s):
10 hypot:10 -> 14.142135623731
10 hypot:20 -> 22.3606797749979
10.0 hypot:10.0 -> 14.142135623731
10.0 hypot:20.0 -> 22.3606797749979
10.0 hypot:20 -> 22.3606797749979
10.0 asQDouble hypot:20 -> 22.36067977
10.0 hypot:20 asQDouble -> 22.36067977
|
-
inverseSqrt
-
compute 1/sqrt(x)
-
moduloNegPiToPi
-
return the receiver modulo 2*pi (i.e. wrap into -pi .. +pi)
Usage example(s):
0.0 negated
(Float pi) moduloNegPiToPi 3.14159265358979
(Float pi * 2) moduloNegPiToPi 0.0
(Float pi * 3) moduloNegPiToPi -3.14159265358979
(Float pi * 4) moduloNegPiToPi 0.0
(Float pi * 5) moduloNegPiToPi -3.14159265358979
(Float pi * -1) moduloNegPiToPi 3.14159265358979
(Float pi * -2) moduloNegPiToPi -0.0
(Float pi * -3) moduloNegPiToPi 3.14159265358979
(Float pi * 5.5) moduloNegPiToPi -1.5707963267949
|
-
sec
-
return the secant of the receiver (interpreted as radians)
-
sin
-
return the sine of the receiver (interpreted as radians)
Usage example(s):
-
tan
-
return the tangens of the receiver (interpreted as radians)
trigonometric (degrees)
-
degreeCos
-
Return the cosine of the receiver taken as an angle in degrees.
-
degreeSin
-
Return the sine of the receiver taken as an angle in degrees.
-
degreeTan
-
Return the cosine of the receiver taken as an angle in degrees.
trigonometric - hyperbolic
-
arCosh
-
return the hyperbolic area cosine of the receiver.
-
arCoth
-
return the inverse hyperbolic cotangent of the receiver.
-
arCsch
-
return the inverse hyperbolic cosecant of the receiver.
-
arSech
-
return the inverse hyperbolic secant of the receiver.
Usage example(s):
should probably be called arSech
|
-
arSinh
-
return the inverse hyperbolic area sine of the receiver.
-
arTanh
-
return the inverse hyperbolic area tangent of the receiver.
-
arcosh
-
return the inverse hyperbolic cosine of the receiver.
Alternative name for compatibility
-
arcoth
-
return the inverse hyperbolic cotangent of the receiver.
Alternative name for compatibility
-
arcsch
-
return the inverse hyperbolic cosecant of the receiver.
Alternative name for compatibility
-
arsech
-
return the inverse hyperbolic secant of the receiver.
Alternative name for compatibility
-
arsinh
-
return the inverse hyperbolic sine of the receiver.
Alternative name for compatibility
-
artanh
-
return the inverse hyperbolic tangent of the receiver.
Alternative name for compatibility
-
cosh
-
return the hyperbolic cosine of the receiver (interpreted as radians)
Usage example(s):
^ self cosh_withAccuracy:self epsilon
|
-
coth
-
return the hyperbolic cotangent of the receiver
-
csch
-
return the hyperbolic cosecant of the receiver (interpreted as radians)
-
sech
-
return the hyperbolic secant of the receiver (interpreted as radians)
-
sinh
-
return the hyperbolic sine of the receiver
Usage example(s):
10 sinh -> 11013.23287470339338
(10 exp - (-10 exp)) / 2 -> 11013.23287470339338
|
-
tanh
-
return the hyperbolic tangens of the receiver
truncation & rounding
-
detentBy: detent atMultiplesOf: grid snap: snap
-
Map all values that are within detent/2 of any multiple of grid
to that multiple.
Otherwise, if snap is true, return self, meaning that the values
in the dead zone will never be returned.
If snap is false, then expand the range between dead zones
so that it covers the range between multiples of the grid,
and scale the value by that factor.
Usage example(s):
(170 to: 190 by: 2) collect: [:a | a detentBy: 10 atMultiplesOf: 90 snap: true]
(170 to: 190 by: 2) collect: [:a | a detentBy: 10 atMultiplesOf: 90 snap: false]
(3.9 to: 4.1 by: 0.02) collect: [:a | a detentBy: 0.1 atMultiplesOf: 1.0 snap: true]
(-3.9 to: -4.1 by: -0.02) collect: [:a | a detentBy: 0.1 atMultiplesOf: 1.0 snap: false]
|
-
fractionPart
-
return a number with value from digits after the decimal point.
i.e. the receiver minus its truncated value,
such that:
(self truncated + self fractionPart) = self
Floats will return an inexact float;
Fractions will return an exact fraction.
ScaledDecimals will return an exact scaled decimal
Usage example(s):
1234.56789 fractionPart -- beware of rounding errors in floats
1234.56789q fractionPart -- beware of rounding errors in floats
1234.56789 asShortFloat fractionPart -- beware of rounding errors in floats
1234.56789s fractionPart -- scaledDecimals do not have this problem
(5/3) fractionPart -- fractions do not have this problem
1.2345e0 fractionPart 0.2345
1.2345e1 fractionPart 0.345000000000001
1.2345e2 fractionPart 0.450000000000003
1.2345e3 fractionPart 0.5
1.2345e4 fractionPart 0.0
1.2345e6 fractionPart 0.0
(1/4) fractionPart (1/4)
(5/4) fractionPart (1/4)
(6/4) fractionPart (1/2)
(8/9) fractionPart (8/9)
(16/10) fractionPart (3/5)
(16/10) truncated 1
(16/10) fractionPart + (16/10) truncated (8/5)
(11/9) fractionPart (2/9)
(11/9) fractionPart + (11/9) truncated (11/9)
1.6 asLongFloat fractionPart + 1.6 asLongFloat truncated -- beware rounding errors in floats
-1.6 asLongFloat fractionPart + -1.6 asLongFloat truncated -> -1.600000000000000089
(16/10) fractionPart + (16/10) truncated -> (8/5)
(5/3) fractionPart -> (2/3)
(5/3) truncated -> 1
(5/3) truncated + (5/3) fractionPart -> (5/3)
((5/3) asScaledDecimal:3) fractionPart -> 0.667
((5/3) asScaledDecimal:3) truncated -> 1
((5/3) asScaledDecimal:3) truncated + ((5/3) asScaledDecimal:3) fractionPart -> 1.667
|
-
integerPart
-
return a number with value from digits before the decimal point.
(i.e. the value truncated towards zero)
such that:
(self integerPart + self fractionPart) = self
Notice that due to rounding errors, the above expression might
be untrue for Floats.
Usage example(s):
1234.56789 integerPart
1.2345e6 integerPart
12.5 integerPart
-12.5 integerPart
(5/3) integerPart
(-5/3) integerPart
(5/3) truncated
(-5/3) truncated
(1234.56789 integerPart + 1234.56789 fractionPart) = 1234.56789
|
-
roundedToScale: scale
-
return the receiver as a scaled decimal, rounded to scale fractional digits
Usage example(s):
123.4567 truncatedToScale:2 -> 123.45
123.4567 roundedToScale:2 -> 123.46
|
-
truncatedAsFloat
-
return the receiver truncated towards zero as an instance of its class.
This is much like #truncated, but avoids a (possibly expensive) conversion
of the result to an integer.
It may be useful, if the result is to be further used in another
float-operation.
** This method must be redefined in concrete classes (subclassResponsibility) **
-
truncatedToScale: scale
-
return the receiver as a scaled decimal, truncated to scale fractional digits
Usage example(s):
123.4567 truncatedToScale:2 -> 123.45
123.4567 roundedToScale:2 -> 123.46
123.4567q roundedToScale:2 -> 123.46
123.4567s5 roundedToScale:2 -> 123.46
123.4567s5 truncatedToScale:2 -> 123.45
|
|