perl6/doc/lib/Real

doc src
(title) role Real
    role Real does Numeric { ... }

 
Common role for non-Complex numbers.

Methods

(head2) Rat
    method Rat(Real:D: Real $epsilon = 1e-6)

 
Converts the number to a Rat with the precision $epsilon .
(head2) rand
    sub term:<rand> returns Num:D
    method rand(Real:D:) returns Real:D

 
Returns a pseudo-random number between zero and the number. The term form returns a pseudo-random Num between 0e0 and 1e0.
(head2) sign
    method sign(Real:D:)

 
Returns -1 if the number is negative, 0 if it is zero and 1 otherwise.
(head2) round
    method round(Real:D: $scale = 1)

 
Rounds the number to scale $scale . If $scale is 1, rounds to an integer. If scale is 0.1 , rounds to one digit after the comma etc.
(head2) floor
    method floor(Real:D) returns Int:D

 
Return the largest integer not greater than the number.
(head2) ceiling
    method ceiling(Real:D) returns Int:D

 
Returns the smallest integer not less than the number.
(head2) truncate
    method truncate(Real:D) returns Int:D

 
Rounds the number towards zero.
(head2) base
    method base(Real:D: Int:D $base where 2..36) returns Str:D

 
Converts the number to a string, using $base as base. For $base larger than ten, capital latin letters are used.
    255.base(16)    # 'FF'

 

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: