Class: RLTK::CG::ConstantReal Abstract

Inherits:
ConstantNumber show all
Includes:
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, PPCFP128, X86FP80

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Methods included from AbstractClass

included

Methods inherited from ConstantNumber

type, #type

Methods inherited from Constant

#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.



934
935
936
937
938
939
940
941
942
943
944
945
# File 'lib/rltk/cg/value.rb', line 934

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:



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

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

#*(rhs) ⇒ ConstantReal

Returns Instance of the same class.

Parameters:

Returns:



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

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

#+(rhs) ⇒ ConstantReal

Returns Instance of the same class.

Parameters:

Returns:



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

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

#-(rhs) ⇒ ConstantReal

Returns Instance of the same class.

Parameters:

Returns:



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

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

#-@ConstantReal

Returns Instance of the same class.

Returns:



950
951
952
# File 'lib/rltk/cg/value.rb', line 950

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

#/(rhs) ⇒ ConstantReal

Returns Instance of the same class.

Parameters:

Returns:



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

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:



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

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:



1007
1008
1009
# File 'lib/rltk/cg/value.rb', line 1007

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.



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

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:

  • [



1026
1027
1028
# File 'lib/rltk/cg/value.rb', line 1026

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.



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

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