Class: Axiom::Function::Numeric::SquareRoot

Inherits:
Axiom::Function::Numeric show all
Includes:
Unary, Unary::Invertible
Defined in:
lib/axiom/function/numeric/square_root.rb

Overview

A class representing a square root function

Defined Under Namespace

Modules: Methods

Instance Attribute Summary

Attributes included from Operation::Unary

#operand

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Unary

#call, #rename

Methods included from Unary::Callable

#call, #included

Methods included from Operation::Unary

#initialize

Methods inherited from Axiom::Function

extract_value, rename_attributes

Methods included from Visitable

#accept

Class Method Details

.call(value) ⇒ Numeric

Return the square root of the value

Examples:

square_root = SquareRoot.call(value)

Parameters:

Returns:



23
24
25
# File 'lib/axiom/function/numeric/square_root.rb', line 23

def self.call(value)
  Math.sqrt(value)
end

.typeClass<Types::Float>

Return the type returned from #call

Examples:

type = Axiom::Function::Numeric::SquareRoot.type
# => Axiom::Types::Float

Returns:

  • (Class<Types::Float>)


36
37
38
# File 'lib/axiom/function/numeric/square_root.rb', line 36

def self.type
  Types::Float
end

Instance Method Details

#inverseExponentiation

Return the inverse function

Examples:

inverse = square_root.inverse

Returns:



48
49
50
# File 'lib/axiom/function/numeric/square_root.rb', line 48

def inverse
  Exponentiation.new(operand, 2).memoize(inverse: self)
end

#typeClass<Types::Float>

Return the type returned from #call

Examples:

type = square_root.type  # => Axiom::Types::Float

Returns:

  • (Class<Types::Float>)


60
61
62
# File 'lib/axiom/function/numeric/square_root.rb', line 60

def type
  self.class.type
end