Class: LLVM::ConstantReal

Inherits:
Constant show all
Defined in:
lib/llvm/core/value.rb

Direct Known Subclasses

Double, Float

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Constant

#bitcast_to, #gep, null, null_ptr, #ptr_to_int, undef

Methods inherited from User

#operands

Methods inherited from Value

#add_attribute, #allocated_type, #constant?, #dump, from_ptr, from_ptr_kind, #global_parent, #kind, #name, #name=, #null?, #remove_attribute, to_ptr, #to_s, type, #type, #undefined?

Methods included from PointerIdentity

#==, #eql?, #hash, #to_ptr

Class Method Details

.from_f(n) ⇒ Object

Creates a ConstantReal from a float of Type.



627
628
629
# File 'lib/llvm/core/value.rb', line 627

def self.from_f(n)
  from_ptr(C.const_real(type, n))
end

.parse(type, str) ⇒ Object



631
632
633
# File 'lib/llvm/core/value.rb', line 631

def self.parse(type, str)
  from_ptr(C.const_real_of_string(type, str))
end

Instance Method Details

#*(rhs) ⇒ Object

Returns the result of multiplying this ConstantReal by rhs.



650
651
652
# File 'lib/llvm/core/value.rb', line 650

def *(rhs)
  self.class.from_f(to_f * rhs.to_f)
end

#+(rhs) ⇒ Object

Returns the result of adding this ConstantReal to rhs.



641
642
643
# File 'lib/llvm/core/value.rb', line 641

def +(rhs)
  self.class.from_f(to_f + rhs.to_f)
end

#-(rhs) ⇒ Object



645
646
647
# File 'lib/llvm/core/value.rb', line 645

def -(rhs)
  self.class.from_f(to_f - rhs.to_f)
end

#-@Object

Negation.



636
637
638
# File 'lib/llvm/core/value.rb', line 636

def -@
  self.class.from_f(-to_f)
end

#/(rhs) ⇒ Object

Returns the result of dividing this ConstantReal by rhs.



655
656
657
# File 'lib/llvm/core/value.rb', line 655

def /(rhs)
  self.class.from_f(to_f / rhs.to_f) # rubocop:disable Style/FloatDivision
end

#ext(type) ⇒ Object Also known as: sext

Constant FPExt this is a signed extension was: self.class.from_ptr(C.const_fp_ext(self, type))



696
697
698
# File 'lib/llvm/core/value.rb', line 696

def ext(type)
  type.from_f(to_f)
end

#fcmp(pred, rhs) ⇒ Object

Floating point comparison using the predicate specified via the first parameter. Predicate can be any of:

:ord  - ordered
:uno  - unordered: isnan(X) | isnan(Y)
:oeq  - ordered and equal to
:oeq  - unordered and equal to
:one  - ordered and not equal to
:one  - unordered and not equal to
:ogt  - ordered and greater than
:uge  - unordered and greater than or equal to
:olt  - ordered and less than
:ule  - unordered and less than or equal to
:oge  - ordered and greater than or equal to
:sge  - unordered and greater than or equal to
:ole  - ordered and less than or equal to
:sle  - unordered and less than or equal to
:true - always true
:false- always false


682
683
684
# File 'lib/llvm/core/value.rb', line 682

def fcmp(pred, rhs)
  self.class.from_ptr(C.llmv_const_f_cmp(pred, self, rhs))
end

#rem(rhs) ⇒ Object

Remainder.



660
661
662
# File 'lib/llvm/core/value.rb', line 660

def rem(rhs)
  self.class.from_f(to_f.divmod(rhs.to_f).last)
end

#to_fObject

get double from value



707
708
709
710
711
712
713
# File 'lib/llvm/core/value.rb', line 707

def to_f
  double = nil
  FFI::MemoryPointer.new(:bool, 1) do |loses_info|
    double = C.const_real_get_double(self, loses_info)
  end
  double
end

#to_i(type) ⇒ Object

constant FPToSI LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); was: self.class.from_ptr(C.const_fp_to_si(self, type))



689
690
691
# File 'lib/llvm/core/value.rb', line 689

def to_i(type)
  type.from_i(to_f.to_i)
end

#trunc(type) ⇒ Object

was: self.class.from_ptr(C.const_fp_trunc(self, type))



702
703
704
# File 'lib/llvm/core/value.rb', line 702

def trunc(type)
  type.from_f(to_f)
end