Class: FloatPowerInstruction
- Inherits:
-
Instruction
- Object
- Instruction
- FloatPowerInstruction
- Defined in:
- lib/instructions/float/float_power.rb
Overview
pops the top 2 items of the :float
stack; pushes a ValuePoint with value x**y, where x is the second stack item, y the top one
note: the top item is the exponent, the second item is the base
note: will push an :error
ValuePoint instead of a :float
if the operation doesn’t return a float
needs: 2 :float
pushes: 1 :float
Instance Attribute Summary
Attributes inherited from Instruction
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
#cleanup ⇒ Object
29 30 31 |
# File 'lib/instructions/float/float_power.rb', line 29 def cleanup pushes :float, @result end |
#derive ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/instructions/float/float_power.rb', line 21 def derive if !(@base**@exp).nan? @result = ValuePoint.new("float", @base**@exp) else raise Instruction::NaNResultError, "#{self.class.to_nudgecode} did not return a float" end end |
#preconditions? ⇒ Boolean
14 15 16 |
# File 'lib/instructions/float/float_power.rb', line 14 def preconditions? needs :float, 2 end |
#setup ⇒ Object
17 18 19 20 |
# File 'lib/instructions/float/float_power.rb', line 17 def setup @exp = @context.pop_value(:float) @base = @context.pop_value(:float) end |