Sha256: 5dd289f073d96d46ad7143a7408c647c347df5d9229fc20d6ad7501acc637fe1

Contents?: true

Size: 832 Bytes

Versions: 10

Compression:

Stored size: 832 Bytes

Contents

module BigMath

  N_ONE = -1.to_d
  ZERO = 0.to_d
  ONE = 1.to_d
  TWO = 2.to_d

  # http://en.wikipedia.org/wiki/Atan2#Definition_and_computation
  #
  def self.atan2 y, x, precision
    case
    when x > ZERO
      BigMath.atan((y / x), precision)
    when y >= ZERO && x < ZERO
      BigMath.atan((y / x), precision) + Terraformer::PI
    when y < ZERO && x < ZERO
      BigMath.atan((y / x), precision) - Terraformer::PI
    when x == ZERO
      case
      when y > ZERO
        Terraformer::PI / TWO
      when y < ZERO
        -(Terraformer::PI / TWO)
      when y == ZERO
        BigDecimal::NAN
      end
    end
  end

  # http://en.wikipedia.org/wiki/Trigonometric_functions#Right-angled_triangle_definitions
  #
  def self.tan theta, precision
    BigMath.sin(theta, precision) / BigMath.cos(theta, precision)
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
terraformer-0.2.1 lib/ext/big_math.rb
terraformer-0.2.0 lib/ext/big_math.rb
terraformer-0.1.0 lib/ext/big_math.rb
terraformer-0.0.9 lib/ext/big_math.rb
terraformer-0.0.8 lib/ext/big_math.rb
terraformer-0.0.7 lib/ext/big_math.rb
terraformer-0.0.6 lib/ext/big_math.rb
terraformer-0.0.4 lib/ext/big_math.rb
terraformer-0.0.3 lib/ext/big_math.rb
terraformer-0.0.2 lib/ext/big_math.rb