edu.vub.at.objects
Interface Number


 Number

ATNumber is the public interface to an AmbientTalk native number (an integer value).

Author:
tvc

Method Summary
 Number /-(Number nbr)
          Returns the floor division between the number and another number passed as argument.
 Fraction ??(Number nbr)
          Returns a random fraction in the exclusive range from the number to a number passed as argument.
 Number %(Number nbr)
          Returns the modular arithmetic between the number and another number passed as argument.
 Table ***(Number end)
          Returns a table containing the inclusive range from the number to a number passed as argument.
 Table **(Number end)
          Returns a table containing the exclusive range from the number to a number passed as argument.
 Number abs()
          Returns the absolute value of a number.
 Number dec()
          Returns the number minus 1.
 Nil doTimes:(Closure code)
          Iterates as many times as the value of the number applying a closure passed as argument.
 Number inc()
          Returns the number plus 1.
  millisec()
          Converts an AmbientTalk number representing a time period in milliseconds into a Java long representing the same time period in milliseconds.
  minutes()
          Converts an AmbientTalk number representing a minute time period into a Java long * 1000 * 60 representing a millisecond time period.
  seconds()
          Converts an AmbientTalk number representing a time period in seconds into a Java long * 1000 representing a time period in milliseconds.
 Nil to:do:(Number end, Closure code)
          Iterates from the value of the receiver to the one passed as argument applying a closure.
 Nil to:step:do:(Number end, Number inc, Closure code)
          Iterates from the value of the receiver to the one passed as argument applying a closure.
 
Methods inherited from interface edu.vub.at.objects.Numeric
/, =, >=, >, <=>, <=, <, -, !=, +, *, addFraction, addNumber, ceiling, cos, divideFraction, divideNumber, expt, floor, gequalsFraction, gequalsNumber, log, round, sin, sqrt, subtractFraction, subtractNumber, tan, timesFraction, timesNumber, toText
 
Methods inherited from interface edu.vub.at.objects.AbstractGrammar
freeVariables
 
Methods inherited from interface edu.vub.at.objects.Object
super
 

Method Detail

inc

Number inc()
Returns the number plus 1.

Returns:
an ATNumber resulting of adding 1 to the receiver.

dec

Number dec()
Returns the number minus 1.

Returns:
an ATNumber resulting of subtracting 1 to the receiver.

abs

Number abs()
Returns the absolute value of a number.

More specifically:

Returns:
the absolute value of the receiver.

doTimes:

Nil doTimes:(Closure code)
Iterates as many times as the value of the number applying a closure passed as argument.

More specifically, the equivalent pseudo-code for this construct is: for i = 1 to receiver do code.eval(i); nil

Here comes an example about how the doTimes: construct can be used to calculate the factorial of a number. def fact(n) { def res := 1; n.doTimes: { |i| res := res * i}; res }

Parameters:
code - a closure expected to take one argument to be applied in each iteration
Returns:
nil
Throws:
edu.vub.at.exceptions.InterpreterException - if raised inside the iterator block.

to:do:

Nil to:do:(Number end,
           Closure code)
Iterates from the value of the receiver to the one passed as argument applying a closure.

More specifically, this method calls: receiver.to: end step: 1 do: { |i| code }

The end boundary is inclusive. If end is bigger than the receiver, the code block is not executed. For such uses, use downTo:do: instead.

Parameters:
end - a number representing the stop value of the loop.
code - a closure expected to take one argument to be applied in each iteration.
Returns:
nil
Throws:
edu.vub.at.exceptions.InterpreterException - if raised inside the iterator block.

to:step:do:

Nil to:step:do:(Number end,
                Number inc,
                Closure code)
Iterates from the value of the receiver to the one passed as argument applying a closure.

More specifically, the equivalent pseudo-code for this method is:

for (i = receiver; i < end ; i := i + inc) do code.eval(i); nil

Note that if end is bigger than the receiver, the construct behaves as a down-to operation. If receiver is equals to end, the code is not executed.

Parameters:
end - a number representing the stop value of the loop.
inc - a number representing the step value of the loop.
code - a closure expected to take one argument to be applied in each iteration.
Returns:
nil
Throws:
edu.vub.at.exceptions.InterpreterException - if raised inside the iterator block.

**

Table **(Number end)
Returns a table containing the exclusive range from the number to a number passed as argument.

Usage example:

2 ** 5 => [ 2, 3, 4 ] 5 ** 2 => [ 5, 4, 3 ]

Parameters:
end - a number representing the stop value of the range.
Returns:
a Table representing [ receiver, ..., end [

***

Table ***(Number end)
Returns a table containing the inclusive range from the number to a number passed as argument.

Usage example:

2 *** 5 => [ 2, 3, 4, 5 ] 5 *** 2 => [ 5, 4, 3, 2 ]

Parameters:
end - a number representing the stop value of the range.
Returns:
a Table representing [ receiver, ..., end ]

??

Fraction ??(Number nbr)
Returns a random fraction in the exclusive range from the number to a number passed as argument.

Parameters:
nbr - a number representing the stop value of the range.
Returns:
the Fraction chosen randomly in [ receiver, ..., nbr [

%

Number %(Number nbr)
Returns the modular arithmetic between the number and another number passed as argument.

Parameters:
nbr - a number.
Returns:
an Number resulting of the remainder of the division (of receiver by nbr) that truncates towards zero.

/-

Number /-(Number nbr)
Returns the floor division between the number and another number passed as argument.

Parameters:
nbr - a number.
Returns:
a Number resulting of the floor division of receiver by nbr.

millisec

 millisec()
Converts an AmbientTalk number representing a time period in milliseconds into a Java long representing the same time period in milliseconds.

Returns:
a Java long representation of self.

seconds

 seconds()
Converts an AmbientTalk number representing a time period in seconds into a Java long * 1000 representing a time period in milliseconds.

Returns:
a Java long representation of self * 1000.

minutes

 minutes()
Converts an AmbientTalk number representing a minute time period into a Java long * 1000 * 60 representing a millisecond time period.

Returns:
a Java long representation of self * 1000 * 60.