| kind | = | "Number Decimal" |
An exact, unlimited representation of a decimal number
- *(multiplier)
- +(addend)
- -(subtrahend)
- /(divisor)
- <=>(other)
- ==(other)
- ===(other)
- asText()
- hash()
- inspect()
- notice()
returns the product of this number and the argument. if the argument is a rational, the receiver will be converted into a form suitable for multiplying against a decimal, and then multiplied. if the argument is neither a Rational nor a Decimal, it tries to call asDecimal, and if that fails it signals a condition.
- - should multiply with 0.0
[ show source ]
(1.0 *(0.0)) should ==(0.0) (34253453.0 *(0.0)) should ==(0.0) (-(1.0) *(0.0)) should ==(0.0)
- - should return the same number when multiplying with 1.0
[ show source ]
(1.0 *(1.0)) should ==(1.0) (34253453.1 *(1.0)) should ==(34253453.1) (-(1.0) *(1.0)) should ==(-(1.0))
- - should return a really large number when multiplying large numbers
[ show source ]
(2345346456745722.0 *(12213212323899088545.0)) should ==(28644214249339912541248622627954490.0)
- - should return a negative number when multiplying with one negative number
[ show source ]
(-(21.0) *(2.0)) should ==(-(42.0))
- - should return a positive number when multiplying with two negative numbers
[ show source ]
(-(21.0) *(-(2.0))) should ==(42.0)
- - should convert its argument to a decimal if its not a decimal
[ show source ]
(0.6 *(2)) should ==(1.2) (1.2 *(3)) should ==(3.6)
- - should convert its argument to a decimal with asDecimal if its not a decimal and not a rational
[ show source ]
x = Origin mimic x asDecimal = method(21.2) (2.0 *(x)) should ==(42.4)
- - should signal a condition if it isn't a decimal and can't be converted
[ show source ]
fn(1.0 *(Origin mimic)) should signal(Condition Error Type IncorrectType)
- - should validate type of receiver
[ show source ]
Number Decimal should checkReceiverTypeOn(:("*"), 2)
returns the sum of this number and the argument. if the argument is a rational, it will be converted into a form suitable for addition against a decimal, and then added. if the argument is neither a Rational nor a Decimal, it tries to call asDecimal, and if that fails it signals a condition.
- - should return 0.0 for the sum of 0.0 and 0.0
[ show source ]
(0.0 +(0.0)) should ==(0.0)
- - should return the sum of really large numbers
[ show source ]
(234235345636345634567345675467.1 +(1.2)) should ==(234235345636345634567345675468.3) (21342342342345345.0 +(778626453756754687567865785678.1)) should ==(778626453756776029910208131023.1) (234234.0 +(63456345745676574567571345456345645675674567878567856785678657856568768.0)) should ==(63456345745676574567571345456345645675674567878567856785678657856803002.0)
- - should return the sum of smaller numbers
[ show source ]
(1.0 +(1.1)) should ==(2.1) (10.0 +(1.0)) should ==(11.0) (15.5 +(15.0)) should ==(30.5) (16.0 +(15.0)) should ==(31.0)
- - should return the sum of negative numbers
[ show source ]
(1.0 +(0.0 -(1.0))) should ==(0.0) ((0.0 -(1.0)) +(2.0)) should ==(1.0) ((0.0 -(1.0)) +(0.0 -(1.0))) should ==(-(2.0))
- - should return the number when 0.0 is the receiver
[ show source ]
(0.0 +(1.0)) should ==(1.0) (0.0 +(0.0 -(1.0))) should ==(-(1.0)) (0.0 +(124423.0)) should ==(124423.0) (0.0 +(34545636745678657856786786785678.1)) should ==(34545636745678657856786786785678.1)
- - should return the number when 0.0 is the argument
[ show source ]
(1.3 +(0.0)) should ==(1.3) ((0.0 -(1.0)) +(0.0)) should ==(-(1.0)) (124423.0 +(0.0)) should ==(124423.0) (34545636745678657856786786785678.0 +(0.0)) should ==(34545636745678657856786786785678.0)
- - should convert its argument to a decimal if its not a decimal
[ show source ]
(0.6 +(1)) should ==(1.6) (1.2 +(3)) should ==(4.2)
- - should convert its argument to a decimal with asDecimal if its not a decimal and not a rational
[ show source ]
x = Origin mimic x asDecimal = method(41.1) (1.1 +(x)) should ==(42.2)
- - should signal a condition if it isn't a decimal and can't be converted
[ show source ]
fn(1.0 +(Origin mimic)) should signal(Condition Error Type IncorrectType)
- - should validate type of receiver
[ show source ]
Number Decimal should checkReceiverTypeOn(:("+"), 2)
returns the difference between this number and the argument. if the argument is a rational, it will be converted into a form suitable for subtracting against a decimal, and then subtracted. if the argument is neither a Rational nor a Decimal, it tries to call asDecimal, and if that fails it signals a condition.
- - should return 0.0 for the difference between 0.0 and 0.0
[ show source ]
(0.0 -(0.0)) should ==(0.0)
- - should return the difference between really large numbers
[ show source ]
(123435334645674745675675757.1 -(123435334645674745675675756.1)) should ==(1.0) (123435334645674745675675757.2 -(1.1)) should ==(123435334645674745675675756.1) (123435334645674745675675757.0 -(24334534544345345345345.0)) should ==(123411000111130400330330412.0)
- - should return the difference between smaller numbers
[ show source ]
(0.0 -(1.0)) should ==(-(1.0)) (2.0 -(1.0)) should ==(1.0) (10.0 -(5.0)) should ==(5.0) (234.0 -(30.0)) should ==(204.0) (30.0 -(35.0)) should ==(-(5.0))
- - should return the difference between negative numbers
[ show source ]
((-(1.0)) -(1.0)) should ==(-(2.0)) ((-(1.0)) -(5.0)) should ==(-(6.0)) ((-(1.0)) -(-(5.0))) should ==(4.0) ((-(10.0)) -(5.0)) should ==(-(15.0)) ((-(10.0)) -(0.0 -(5.0))) should ==(-(5.0)) ((-(2545345345346547456756.0)) -(-(2545345345346547456755.0))) should ==(-(1.0))
- - should return the number when 0 is the argument
[ show source ]
((-(1.0)) -(0.0)) should ==(-(1.0)) (10.0 -(0.0)) should ==(10.0) (1325234534634564564576367.0 -(0.0)) should ==(1325234534634564564576367.0)
- - should convert its argument to a decimal if its not a decimal
[ show source ]
(1.6 -(1)) should ==(0.6) (3.2 -(2)) should ==(1.2)
- - should convert its argument to a decimal with asDecimal if its not a decimal and not a rational
[ show source ]
x = Origin mimic x asDecimal = method(42.0) (43.4 -(x)) should ==(1.4)
- - should signal a condition if it isn't a number and can't be converted
[ show source ]
fn(1 -(Origin mimic)) should signal(Condition Error Type IncorrectType)
- - should validate type of receiver
[ show source ]
Number Decimal should checkReceiverTypeOn(:("-"), 2)
returns the quotient of this number and the argument.
- - should cause a condition when dividing with 0.0
[ show source ]
fn(10.0 /(0.0)) should signal(Condition Error Arithmetic DivisionByZero)
- - should divide simple numbers
[ show source ]
(2.0 /(1.0)) should ==(2.0) (4.2 /(2.0)) should ==(2.1) (200.0 /(5.0)) should ==(40.0)
- - should divide negative numbers correctly
[ show source ]
(-(8200.0) /(10.0)) should ==(-(820.0))
- - should divide with a negative dividend correctly
[ show source ]
(8200.0 /(-(10.0))) should ==(-(820.0))
- - should correctly handle a number that would generate an infinite expansion, by being inexact
[ show source ]
(2.0 /(3.0)) should ==(0.6666666666666666666666666666666667)
- - should divide a negative number with a negative dividend
[ show source ]
(-(8200.0) /(-(10.0))) should ==(820.0)
- - should convert its argument to a decimal if its not a decimal
[ show source ]
(0.5 /(5)) should ==(0.1) (3.4 /(2)) should ==(1.7)
- - should convert its argument to a decimal with asDecimal if its not a decimal and not a rational
[ show source ]
x = Origin mimic x asDecimal = method(2.0) (42.8 /(x)) should ==(21.4)
- - should signal a condition if it isn't a decimal and can't be converted
[ show source ]
fn(1.0 /(Origin mimic)) should signal(Condition Error Type IncorrectType)
- - should validate type of receiver
[ show source ]
Number Decimal should checkReceiverTypeOn(:("/"), 2)
compares this number against the argument, returning -1, 0 or 1 based on which one is larger. if the argument is a rational, it will be converted into a form suitable for comparing against a decimal, and then compared. if the argument is neither a Rational nor a Decimal, it tries to call asDecimal, and if that doesn't work it returns nil.
- - should return 0 for the same number
[ show source ]
(0.0 <=>(0.0)) should ==(0) (1.0 <=>(1.0)) should ==(0) (10.0 <=>(10.0)) should ==(0) (12413423523452345345345.0 <=>(12413423523452345345345.0)) should ==(0) ((0.0 -(1.0)) <=>(0.0 -(1.0))) should ==(0) (1.2 <=>(1.2)) should ==(0)
- - should return 1 when the left number is larger than the right
[ show source ]
(1.0 <=>(0.0)) should ==(1) (2.0 <=>(1.0)) should ==(1) (10.0 <=>(9.0)) should ==(1) (12413423523452345345345.0 <=>(12413423523452345345344.0)) should ==(1) (0.0 <=>(-(1.0))) should ==(1) (1.0 <=>(-(1.0))) should ==(1) (0.001 <=>(0.0009)) should ==(1) (0.2 <=>(0.1)) should ==(1)
- - should return -1 when the left number is smaller than the right
[ show source ]
(0.0 <=>(1.0)) should ==(-(1)) (1.0 <=>(2.0)) should ==(-(1)) (9.0 <=>(10.0)) should ==(-(1)) (12413423523452345345343.0 <=>(12413423523452345345344.0)) should ==(-(1)) ((-(1.0)) <=>(0.0)) should ==(-(1)) ((-(1.0)) <=>(1.0)) should ==(-(1)) (0.0009 <=>(0.001)) should ==(-(1)) (0.1 <=>(0.2)) should ==(-(1))
- - should convert argument to a decimal if the argument is a rational
[ show source ]
(1.0 <=>(1)) should ==(0) (1.1 <=>(1)) should ==(1) (0.9 <=>(1)) should ==(-(1))
- - should convert its argument to a decimal if its not a rational or a decimal
[ show source ]
x = Origin mimic x asDecimal = method(42.0) (42.0 <=>(x)) should ==(0)
- - should return nil if it can't be converted and there is no way of comparing
[ show source ]
(1.0 <=>(Origin mimic)) should be nil
- - should validate type of receiver
[ show source ]
Number Decimal should checkReceiverTypeOn(:("<=>"), 2)
compares this number against the argument, true if this number is the same, otherwise false
- - should return true for the same number
[ show source ]
x = 1.0 x should ==(x) x = 10.0 x should ==(x) x = -(20.0) x should ==(x)
- - should not return true for unequal numbers
[ show source ]
1.1 should not ==(2.0) 1.2 should not ==(200000.0) 1123223.3233223 should not ==(65756756756.0) (-(1.0)) should not ==(2.0)
- - should return true for the result of equal number calculations
[ show source ]
(1.0 +(1.0)) should ==(2.0) (2.1 +(1.0)) should ==((1.1 +(2.0)))
- - should work correctly when comparing zeroes
[ show source ]
0.0 should ==(0.0) 1.0 should not ==(0.0) 0.0 should not ==(1.0)
- - should work correctly when comparing negative numbers
[ show source ]
(-(19.1)) should ==((-(19.1))) (-(19.0)) should not ==((-(20.1)))
- - should work correctly when comparing large positive numbers
[ show source ]
123234534675676786789678985463456345.234234 should ==(123234534675676786789678985463456345.234234) 8888856676776.0101 should ==(8888856676776.0101)
- - should convert its argument to a decimal if it is a rational
[ show source ]
2.0 should ==(2) 2.1 should not ==(2)
- - should return false for comparisons against unrelated objects
[ show source ]
2.1 should not ==("foo") 2.1 should not ==(:blarg) - - should validate type of receiver
[ show source ]
Number Decimal should checkReceiverTypeOn(:("=="), 2) - - should work inside of arrays and dicts
[ show source ]
[](1.0) should ==([](1.0)) {}(a: 1.0) should ==({}(a: 1.0))
nil
[ show source ]
method(other,
if(self same?(
0.0),
Reflector other:mimics?(cell(:other),
0.0),
bind(rescue(Condition Error, fn(c, false)),
self ==(
other))))
- - should check for mimicness if receiver is Number Decimal
[ show source ]
Number Decimal should ===(Number Decimal) Number Decimal should ===(123.3) Number Decimal should not ===(123) Number Decimal should not ===((1 /(3))) Number Decimal should not ===(Number) Number Decimal should not ===(Number Real) Number Decimal should not ===(Number Rational) Number Decimal should not ===(Origin)
- - should check for equalness if receiver is not Number Decimal
[ show source ]
0.0 should ===(0.0) 0.0 should not ===(1.0) (-(234.3)) should ===(-(234.3)) 12434 should not ===(0.0) 12434.1 should ===(12434.1)
Returns a text inspection of the object
- - should return the textual representation of the number
[ show source ]
0.1 inspect should ==("0.1") 22342340.1 inspect should ==("22342340.1") 333391244.1 inspect should ==("333391244.1") - - should return the textual representation of a negative number
[ show source ]
(-(1.1)) inspect should ==("-1.1") (-(22342340.1)) inspect should ==("-22342340.1") (-(333391244.1)) inspect should ==("-333391244.1")
Returns a brief text inspection of the object
- - should return the textual representation of the number
[ show source ]
0.0 notice should ==("0.0") 1.0 notice should ==("1.0") 1.3434534534534263456345 notice should ==("1.3434534534534263456345") 1.000000000000000 notice should ==("1.0") 1e3 notice should ==("1000.0") 22342340.0 notice should ==("22342340.0") 333391244.0 notice should ==("333391244.0") - - should return the textual representation of a negative number
[ show source ]
(-(1.0)) notice should ==("-1.0") (-(22342340.0)) notice should ==("-22342340.0") (-(333391244.0)) notice should ==("-333391244.0")