Class: Numeric

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
mrblib/numeric.rb,
src/numeric.c,
mrbgems/mruby-rational/mrblib/rational.rb,
mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb

Overview

Numeric

ISO 15.2.7

Direct Known Subclasses

Complex, Float, Integer, Rational

Instance Method Summary collapse

Methods included from Comparable

#<, #<=, #==, #>, #>=, #between?, #clamp

Instance Method Details

#+@Object

Returns the receiver simply.

ISO 15.2.7.4.1



11
12
13
# File 'mrblib/numeric.rb', line 11

def +@
  self
end

#-@Object

Returns the receiver’s value, negated.

ISO 15.2.7.4.2



19
20
21
# File 'mrblib/numeric.rb', line 19

def -@
  0 - self
end

#absObject

Returns the absolute value of the receiver.

ISO 15.2.7.4.3



27
28
29
30
31
32
33
# File 'mrblib/numeric.rb', line 27

def abs
  if self < 0
    -self
  else
    self
  end
end

#finite?Boolean

15.2.7

Returns:

  • (Boolean)


1576
1577
1578
1579
1580
# File 'src/numeric.c', line 1576

static mrb_value
num_finite_p(mrb_state *mrb, mrb_value self)
{
  return mrb_true_value();
}

#infinite?Boolean

Returns:

  • (Boolean)


1582
1583
1584
1585
1586
# File 'src/numeric.c', line 1582

static mrb_value
num_infinite_p(mrb_state *mrb, mrb_value self)
{
  return mrb_false_value();
}

#negative?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb', line 18

def negative?
  self < 0
end

#nonzero?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
# File 'mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb', line 6

def nonzero?
  if self == 0
    nil
  else
    self
  end
end

#positive?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb', line 14

def positive?
  self > 0
end

#to_rObject



80
81
82
# File 'mrbgems/mruby-rational/mrblib/rational.rb', line 80

def to_r
  Rational(self, 1)
end

#zero?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb', line 2

def zero?
  self == 0
end