- live browsing of Self object memory -

lobby traitsfloat

CopyDowns: vector

CreatorPath: traits float

Modules: float, int32and64

parent* = traits number

arithmetic

% =
( 
     asFloat _FloatMod: a IfFail: [| :error. :name. |
    "Return receiver a receiver. Obeys identity: a%b = a - (b * a/b)."
        ('badTypeError' == error) ifTrue: [
            " use double dispatching "
            a moduloFloat: asFloat ] False: [
        primitiveFailedError: error Name: name ]])
* =
( 
     asFloat _FloatMul: a IfFail: [| :error. :name. |
    ('badTypeError' == error) ifTrue: [
        " use double dispatching "
        a multiplyFloat: asFloat ] False: [
    primitiveFailedError: error Name: name ]])
+ =
( 
     asFloat _FloatAdd: a IfFail: [| :error. :name. |
    ('badTypeError' == error) ifTrue: [
        " use double dispatching "
        a addFloat: asFloat ] False: [
    primitiveFailedError: error Name: name ]])
- =
( 
     asFloat _FloatSub: a IfFail: [| :error. :name. |
    ('badTypeError' == error) ifTrue: [
        " use double dispatching "
        a subtractFloat: asFloat ] False: [
    primitiveFailedError: error Name: name ]])
/ =
( 
     asFloat _FloatDiv: a IfFail: [| :error. :name. |
    ('badTypeError' == error) ifTrue: [
        " use double dispatching "
        a divideFloat: asFloat ] False: [
    primitiveFailedError: error Name: name ]])
/+ = ( (/ a) ceil asInteger)
/- = ( (/ a) floor asInteger)
/= = ( / a)
/~ = ( / a)
addBigInteger: = ( a asFloat + asFloat)_
addSmallInteger: = ( a asFloat + asFloat)_
divideBigInteger: = ( a asFloat / asFloat)_
divideSmallInteger: = ( a asFloat / asFloat)_
moduloBigInteger: = ( a asFloat % asFloat)_
moduloSmallInteger: = ( a asFloat % asFloat)_
multiplyBigInteger: = ( a asFloat * asFloat)_
multiplySmallInteger: = ( a asFloat * asFloat)_
subtractBigInteger: = ( a asFloat - asFloat)_
subtractSmallInteger: = ( a asFloat - asFloat)_
addFloat: = ( a + asFloat)
divideFloat: = ( a / asFloat)
moduloFloat: = ( a % asFloat)
multiplyFloat: = ( a * asFloat)
subtractFloat: = ( a - asFloat)

children

one = 1.0for efficiency (avoid conversions)
two = 2.0for efficiency (avoid conversions)
zero = 0.0for efficiency (avoid conversions)

coercions

asBigInteger = ( asInteger asBigInteger)
asFloat = ( self)
asInt32 = ( int32 fromFloat: self)
asInt64 = ( int64 fromFloat: self)
asInteger = ( asSmallInteger)fix this to handle big floats, too
asSmallIntegerIfFail: = ( asFloat _FloatAsIntIfFail: fb)
ceil = ( asFloat _FloatCeil)
floor = ( asFloat _FloatFloor)
round = ( asFloat _FloatRound)
truncate = ( asFloat _FloatTruncate)these return floats

comparing

!= = ( asFloat _FloatNE: a IfFail: [(= a) not])Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
< =
( 
     asFloat _FloatLT: a IfFail: [
    a reverseLessThanFloat: asFloat])
Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
<= =
( 
     asFloat _FloatLE: a IfFail: [
    a reverseLessThanOrEqualFloat: asFloat])
Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
= =
( 
     asFloat _FloatEQ: a IfFail: [
    a equalsFloat: asFloat])
Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
> =
( 
     asFloat _FloatGT: a IfFail: [
    a reverseGreaterThanFloat: asFloat])
Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
>= =
( 
     asFloat _FloatGE: a IfFail: [
    a reverseGreaterThanOrEqualFloat: asFloat])
Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
compare:IfLess:Equal:Greater: =
( 
    ( 
       _FloatLT: x "Hack! This method is an optimization--dmu"
         IfFail: [^resend.compare: x IfLess: lb Equal: eb Greater: gb]
    ) ifTrue: lb False: [ = x ifTrue: eb False: gb ])
Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
hash = ( identityHash)
compareBigInteger:IfLess:Equal:Greater: = ( asFloat compare: a asFloat IfLess: lb Equal: eb Greater: gb)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though _
equalsBigInteger: = ( asFloat = a asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though _
equalsSmallInteger: = ( a asFloat = asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though _
reverseGreaterThanOrEqualSmallInteger: = ( a asFloat >= asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though _
reverseGreaterThanSmallInteger: = ( a asFloat > asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though _
reverseLessThanOrEqualSmallInteger: = ( a asFloat <= asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though _
reverseLessThanSmallInteger: = ( a asFloat < asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though _
equalsFloat: = ( a = asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
reverseGreaterThanFloat: = ( a > asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
reverseGreaterThanOrEqualFloat: = ( a >= asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
reverseLessThanFloat: = ( a < asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though
reverseLessThanOrEqualFloat: = ( a <= asFloat)Normally would not implement these, but floats are special--dmu By implementing them, we get a good speedup (Hack!) I do not understand why these are double-dispatched, though

functions

reversePower: = ( error: 'fractional exponent')raise to a power; receiver is exponent, argument is base
squareRootPrecision = ( / 10000)

miscellaneous

bitSize = ( typeSizes bitSize: 'self_float')
byteSize = ( typeSizes byteSize: 'self_float')

printing

printString = ( asFloat _FloatPrintString)
printStringPrecision: = ( asFloat _FloatPrintStringPrecision: p asSmallInteger)
storeStringIfFail: =
( | s1 <- ''. s2 <- '' |
    = infinity         ifTrue: [^ ' 1e100 "infinity"'].
    = infinity negate  ifTrue: [^ '-1e100 "negative infinity"'].
    "We have two forms of printStrings for floats. Pick whichever
     causes the least precision loss in this particular case.
     Format 1, obtained by 'printString' may use scientific notation
     like 1e-9, but never (seems to) have more than 6 digits of
     precision. 
     Format 2, obtained by 'printStringPrecision:' may have more digits
     of precision, but seems to never use scientific notation."
    s1: printString.
    absoluteValue >= maxSmallInt ifTrue: [
        "The Self parser is broken! It can't parse a float constant of
         the form 1000000000.345 when the integer part (as in this 
         example) is greater than maxSmallInt. So in this case we 
         should not even consider using this format for storeStrings."
        ^ s1.
    ].
    s2: (printStringPrecision: 8). "8 digits of precision, but
                                     no exponential notation."
    (- s1 eval) absoluteValue compare: (- s2 eval) absoluteValue
                IfLess: s1
                 Equal: [s1 size <= s2 size ifTrue: s1 False: s2]
               Greater: s2)