Class: RLTK::CG::ConstantReal Abstract

Inherits:
ConstantNumber show all
Includes:
Filigree::AbstractClass
Defined in:
lib/rltk/cg/value.rb

Overview

This class is abstract.

All real constants inherit from this class.

Direct Known Subclasses

Double, FP128, Float, Half, PPCFP128, X86FP80

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Methods inherited from ConstantNumber

type, #type

Methods inherited from Constant

#addr_space_cast, #bitcast_to, #get_element_ptr, #get_element_ptr_in_bounds

Methods inherited from User

#operands

Methods inherited from Value

#==, #attributes, #bitcast, #constant?, #dump, #hash, #name, #name=, #null?, #print, #trunc, #trunc_or_bitcast, #type, #undefined?, #zextend, #zextend_or_bitcast

Methods included from BindingClass

#==

Constructor Details

#initialize(num_or_string, size = nil) ⇒ ConstantReal

Create a constant real number using a Ruby value or a string.

Parameters:

  • num_or_string (::Float, String)

    Ruby value or string representation of a float.

  • size (Integer, nil) (defaults to: nil)

    Optional length of string to use.



942
943
944
945
946
947
948
949
950
951
952
953
# File 'lib/rltk/cg/value.rb', line 942

def initialize(num_or_string, size = nil)
	@ptr =
	if num_or_string.is_a?(::Float)
		Bindings.const_real(self.type, num_or_string)
		
	elsif size
		Bindings.const_real_of_string_and_size(self.type, num_or_string, size)
		
	else
		Bindings.const_real_of_string(self.type, num_or_string)
	end
end

Instance Method Details

#%(rhs) ⇒ ConstantReal

Returns Instance of the same class.

Parameters:

Returns:



1003
1004
1005
# File 'lib/rltk/cg/value.rb', line 1003

def %(rhs)
	self.class.new(Bindings.const_f_remm(@ptr, rhs))
end

#*(rhs) ⇒ ConstantReal

Returns Instance of the same class.

Parameters:

Returns:



985
986
987
# File 'lib/rltk/cg/value.rb', line 985

def *(rhs)
	self.class.new(Bindings.const_f_mul(@ptr, rhs))
end

#+(rhs) ⇒ ConstantReal

Returns Instance of the same class.

Parameters:

Returns:



967
968
969
# File 'lib/rltk/cg/value.rb', line 967

def +(rhs)
	self.class.new(Bindings.const_f_add(@ptr, rhs))
end

#-(rhs) ⇒ ConstantReal

Returns Instance of the same class.

Parameters:

Returns:



976
977
978
# File 'lib/rltk/cg/value.rb', line 976

def -(rhs)
	self.class.new(Bindings.const_f_sub(@ptr, rhs))
end

#-@ConstantReal

Returns Instance of the same class.

Returns:



958
959
960
# File 'lib/rltk/cg/value.rb', line 958

def -@
	self.class.new(Bindings.const_f_neg(@ptr))
end

#/(rhs) ⇒ ConstantReal

Returns Instance of the same class.

Parameters:

Returns:



994
995
996
# File 'lib/rltk/cg/value.rb', line 994

def /(rhs)
	self.class.new(Bindings.const_f_div(@ptr, rhs))
end

#cast(type) ⇒ ConstantNumber

Cast this constant real to another number type.

Parameters:

Returns:



1024
1025
1026
# File 'lib/rltk/cg/value.rb', line 1024

def cast(type)
	type.value_class.new(Bindings.const_fp_cast(@ptr, check_cg_type(type, NumberType)))
end

#cmp(pred, rhs) ⇒ Int1

Returns Value used to represent a Boolean value.

Parameters:

  • pred (Symbol)

    An real predicate.

  • rhs (ConstantReal)

    Value to compare to.

Returns:

  • (Int1)

    Value used to represent a Boolean value.

See Also:



1015
1016
1017
# File 'lib/rltk/cg/value.rb', line 1015

def cmp(pred, rhs)
	Int1.new(Bindings.const_f_cmp(pred, @ptr, rhs))
end

#extend(type) ⇒ ConstantReal

Extend a constant real number to a larger size.

Parameters:

  • type (RealType)

    Type to extend to.

Returns:

  • (ConstantReal)

    This value as a real of the given type.



1043
1044
1045
# File 'lib/rltk/cg/value.rb', line 1043

def extend(type)
	type.value_class.new(Bindings.const_fp_ext(@ptr, check_cg_type(type, RealType)))
end

#to_i(type = NativeIntType, signed = true) ⇒ Object

Convert this real number into an integer.

Parameters:

  • type (BasicIntType) (defaults to: NativeIntType)

    Type to convert to.

  • signed (Boolean) (defaults to: true)

    Should the result be a signed integer or not.

Returns:

  • [



1034
1035
1036
# File 'lib/rltk/cg/value.rb', line 1034

def to_i(type = NativeIntType, signed = true)
	type.value_class.new(Bindings.send(signed ? :const_fp_to_si : :const_fp_to_ui, @ptr, check_cg_type(type, BasicIntType)))
end

#truncate(type) ⇒ ConstantReal

Truncate a constant real number to a smaller size.

Parameters:

  • type (RealType)

    Type to truncate to.

Returns:

  • (ConstantReal)

    This value as a real of the given type.



1052
1053
1054
# File 'lib/rltk/cg/value.rb', line 1052

def truncate(type)
	type.value_class.new(Bindings.const_fp_trunc(@ptr, check_cg_type(type, RealType)))
end