Class: FloatPowerInstruction

Inherits:
Instruction show all
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

#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_power.rb', line 29

def cleanup
  pushes :float, @result
end

#deriveObject



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

Returns:

  • (Boolean)


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

def preconditions?
  needs :float, 2
end

#setupObject



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