module BLS::Field
Finite field
Public Instance Methods
==(other)
click to toggle source
# File lib/bls/field.rb, line 16 def ==(other) value == other.value end
add(other)
click to toggle source
# File lib/bls/field.rb, line 35 def add(other) self.class.new(value + other.value) end
Also aliased as: +
div(other)
click to toggle source
# File lib/bls/field.rb, line 61 def div(other) v = other.is_a?(Field) ? other.invert : self.class.new(other).invert multiply(v) end
Also aliased as: /
invert()
click to toggle source
# File lib/bls/field.rb, line 20 def invert x0 = 1 x1 = 0 y0 = 0 y1 = 1 a = self.class.const_get(:ORDER) b = value until a.zero? q, b, a = [b / a, a, b % a] x0, x1 = [x1, x0 - q * x1] y0, y1 = [y1, y0 - q * y1] end self.class.new(x0) end
multiply(other)
click to toggle source
# File lib/bls/field.rb, line 55 def multiply(other) v = other.is_a?(Field) ? other.value : other self.class.new(value * v) end
Also aliased as: *
negate()
click to toggle source
# File lib/bls/field.rb, line 12 def negate self.class.new(-value) end
pow(n)
click to toggle source
# File lib/bls/field.rb, line 44 def pow(n) v = value.pow(n, self.class.const_get(:ORDER)) self.class.new(v) end
Also aliased as: **
square()
click to toggle source
# File lib/bls/field.rb, line 40 def square self.class.new(value**2) end
subtract(other)
click to toggle source
# File lib/bls/field.rb, line 50 def subtract(other) self.class.new(value - other.value) end
Also aliased as: -
zero?()
click to toggle source
# File lib/bls/field.rb, line 8 def zero? value.zero? end