Class: FloatSqrtInstruction

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

Overview

pops the top item of the :float stack; pushes a ValuePoint with its square root onto the :float stack

note: pushes an :error item if the value is negative

needs: 1 :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



25
26
27
# File 'lib/instructions/float/float_sqrt.rb', line 25

def cleanup
  pushes :float, @result
end

#deriveObject



18
19
20
21
22
23
24
# File 'lib/instructions/float/float_sqrt.rb', line 18

def derive
  if @arg1 >= 0.0
    @result = ValuePoint.new("float", Math.sqrt(@arg1))
  else
    raise Instruction::NaNResultError, "#{self.class.to_nudgecode} did not return a float"
  end
end

#preconditions?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/instructions/float/float_sqrt.rb', line 12

def preconditions?
  needs :float, 1
end

#setupObject



15
16
17
# File 'lib/instructions/float/float_sqrt.rb', line 15

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