class BOAST::Modulo
Attributes
operand1[R]
operand2[R]
return_type[R]
Public Class Methods
new(x,y)
click to toggle source
# File lib/BOAST/Language/Operators.rb, line 971 def initialize(x,y) @operand1 = x @operand2 = y op1, op2 = op_to_var @return_type, _ = transition(op1, op2, Modulo) end
Public Instance Methods
pr()
click to toggle source
# File lib/BOAST/Language/Operators.rb, line 983 def pr s="" s << indent s << to_s s << ";" if [C, CL, CUDA].include?( lang ) output.puts s return self end
to_s()
click to toggle source
# File lib/BOAST/Language/Operators.rb, line 978 def to_s return to_s_fortran if lang == FORTRAN return to_s_c if [C, CL, CUDA].include?( lang ) end
to_var()
click to toggle source
# File lib/BOAST/Language/Operators.rb, line 992 def to_var if @return_type then return @return_type.copy( to_s, DISCARD_OPTIONS ) else return Variable::new( to_s, get_default_type ) end end
Private Instance Methods
op_to_var()
click to toggle source
# File lib/BOAST/Language/Operators.rb, line 1037 def op_to_var op1 = @operand1.respond_to?(:to_var) ? @operand1.to_var : @operand1 op1 = @operand1 unless op1 op2 = @operand2.respond_to?(:to_var) ? @operand2.to_var : @operand2 op2 = @operand2 unless op2 return [op1, op2] end
to_s_c()
click to toggle source
# File lib/BOAST/Language/Operators.rb, line 1012 def to_s_c op1, op2 = op_to_var if @return_type and @return_type.type.kind_of?(Real) then if @return_type.type.size <= 4 then return "((#{op1} < 0) ^ (#{op2} < 0) ? fmodf(#{op1}, #{op2}) + #{op2} : fmodf(#{op1}, #{op2}))" else return "((#{op1} < 0) ^ (#{op2} < 0) ? fmod(#{op1}, #{op2}) + #{op2} : fmod(#{op1}, #{op2}))" end else test_op1 = true test_op1 = false if op1.respond_to?(:type) and op1.type.respond_to?(:signed?) and not op1.type.signed? test_op2 = true test_op2 = false if op2.respond_to?(:type) and op2.type.respond_to?(:signed?) and not op2.type.signed? if test_op1 and test_op2 then return "((#{op1} < 0) ^ (#{op2} < 0) ? (#{op1} % #{op2}) + #{op2} : #{op1} % #{op2})" elsif test_op1 then return "( (#{op1} < 0) ? (#{op1} % #{op2.cast(op1)}) + #{op2} : #{op1} % #{op2})" elsif test_op2 then return "( (#{op2} < 0) ? (#{op1.cast(op2)} % #{op2}) + #{op2} : #{op1} % #{op2})" else return "(#{op1} % #{op2})" end end end
to_s_fortran()
click to toggle source
# File lib/BOAST/Language/Operators.rb, line 1002 def to_s_fortran op1, op2 = op_to_var if @return_type and @return_type.type.kind_of?(Real) and ( not op1.type.kind_of?(Real) or not op2.type.kind_of?(Real) ) then return "modulo(real(#{op1}, #{@return_type.type.size}), #{op2})" unless op1.type.kind_of?(Real) return "modulo(#{op1}, real(#{op2}, #{@return_type.type.size}))" else return "modulo(#{op1}, #{op2})" end end