Class: FloatModuloInstruction

Inherits:
Instruction show all
Defined in:
lib/instructions/float/float_modulo.rb

Overview

pops the top 2 items of the :float stack; pushes a ValuePoint with the remainder after dividing the second into the first onto the :float stack

note: the top item is the denominator, the second item is the numerator

note: will push an :error ValuePoint instead of a :float if the numerator is 0.0

needs: 2 :float

pushes: 1 :float

Instance Attribute Summary

Attributes inherited from Instruction

#context

Instance Method Summary collapse

Methods inherited from Instruction

all_instructions, #go, inherited, #initialize, #needs, #pushes, to_nudgecode

Constructor Details

This class inherits a constructor from Instruction

Instance Method Details

#cleanupObject



29
30
31
# File 'lib/instructions/float/float_modulo.rb', line 29

def cleanup
  pushes :float, @result
end

#deriveObject



21
22
23
24
25
26
27
28
# File 'lib/instructions/float/float_modulo.rb', line 21

def derive
  if @arg2 != 0
    @mod = @arg1 % @arg2
    @result = ValuePoint.new("float", @mod)
  else
    raise NaNResultError, "#{self.class} attempted modulo 0.0"
  end
end

#preconditions?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/instructions/float/float_modulo.rb', line 14

def preconditions?
  needs :float, 2
end

#setupObject



17
18
19
20
# File 'lib/instructions/float/float_modulo.rb', line 17

def setup
  @arg2 = @context.pop_value(:float)
  @arg1 = @context.pop_value(:float)
end