Al Newkirk >
Bubblegum-0.27 >
Bubblegum::Object::Number

Module Version: 0.27
Bubblegum::Object::Number - Common Methods for Operating on Numbers

version 0.27

use Bubblegum; my $number = 123456789; say $number->incr; # 123456790

Number methods work on data that meets the criteria for being a number. A number holds and manipulates an arbitrary sequence of bytes, typically representing numberic characters (0-9). It is not necessary to use this module as it is loaded automatically by the Bubblegum class.

my $number = 12; $number->abs; # 12 $number = -12; $number->abs; # 12

The abs method returns the absolute value of the subject.

my $number = 1; $number->atan2(1); # 0.785398163397448

The atan2 method returns the arctangent of Y/X in the range -PI to PI

my $number = 12; $number->cos; # 0.843853958732492

The cos method computes the cosine of the subject (expressed in radians).

my $number = 123456789; $number->decr; # 123456788

The decr method returns the numeric subject decremented by 1.

my $number = 0; $number->exp; # 1 $number = 1; $number->exp; # 2.71828182845905 $number = 1.5; $number->exp; # 4.48168907033806

The exp method returns e (the natural logarithm base) to the power of the subject.

my $number = 175; $number->hex; # 0xaf

The hex method returns a hex string representing the value of the subject.

my $number = 123456789; $number->incr; # 123456790

The incr method returns the numeric subject incremented by 1.

my $number = 12.5; $number->int; # 12

The int method returns the integer portion of the subject. Do not use this method for rounding.

my $number = 12345; $number->log; # 9.42100640177928

The log method returns the natural logarithm (base e) of the subject.

my $number = 12; $number->mod(1); # 0 $number->mod(2); # 0 $number->mod(3); # 0 $number->mod(4); # 0 $number->mod(5); # 2

The mod method returns the division remainder of the subject divided by the argment.

my $number = 12345; $number->neg; # -12345

The neg method returns a negative version of the subject.

my $number = 12345; $number->pow(3); # 1881365963625

The pow method returns a number, the result of a math operation, which is the subject to the power of the argument.

my $number = 12345; $number->sin; # -0.993771636455681

The sin method returns the sine of the subject (expressed in radians).

my $number = 12345; $number->sqrt; # 111.108055513541

The sqrt method returns the positive square root of the subject.

my $int = 1; $int->to_array; # [1]

The to_array method is used for coercion and simply returns an array reference where the first element contains the subject.

my $int = 1; $int->to_code; # sub { 1 }

The to_code method is used for coercion and simply returns a code reference which always returns the subject when called.

my $int = 1; $int->to_hash; # { 1 => 1 }

The to_hash method is used for coercion and simply returns a hash reference with a single key and value, having the key and value both contain the subject.

my $int = 1; $int->to_integer; # 1

The to_integer method is used for coercion and simply returns the subject.

my $int = 1; $int->to_string; # '1'

The to_string method is used for coercion and simply returns the stringified version of the subject.

Bubblegum::Object::Array, Bubblegum::Object::Code, Bubblegum::Object::Hash, Bubblegum::Object::Instance, Bubblegum::Object::Integer, Bubblegum::Object::Number, Bubblegum::Object::Scalar, Bubblegum::Object::String, Bubblegum::Object::Undef, Bubblegum::Object::Universal,

Al Newkirk <anewkirk@ana.io>

This software is copyright (c) 2013 by Al Newkirk.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: