class RLTK::CG::ConstantReal

All real constants inherit from this class.

@abstract

Public Class Methods

new(num_or_string, size = nil) click to toggle source

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

@param [::Float, String] num_or_string Ruby value or string representation of a float. @param [Integer, nil] size Optional length of string to use.

# 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

Public Instance Methods

%(rhs) click to toggle source

Modulo this value by another value.

@param [ConstantReal] rhs

@return [ConstantReal] Instance of the same class.

# File lib/rltk/cg/value.rb, line 1003
def %(rhs)
        self.class.new(Bindings.const_f_remm(@ptr, rhs))
end
*(rhs) click to toggle source

Multiply this value with another value.

@param [ConstantReal] rhs

@return [ConstantReal] Instance of the same class.

# File lib/rltk/cg/value.rb, line 985
def *(rhs)
        self.class.new(Bindings.const_f_mul(@ptr, rhs))
end
+(rhs) click to toggle source

Add this value with another value.

@param [ConstantReal] rhs

@return [ConstantReal] Instance of the same class.

# File lib/rltk/cg/value.rb, line 967
def +(rhs)
        self.class.new(Bindings.const_f_add(@ptr, rhs))
end
-(rhs) click to toggle source

Subtract a value from this value.

@param [ConstantReal] rhs

@return [ConstantReal] Instance of the same class.

# File lib/rltk/cg/value.rb, line 976
def -(rhs)
        self.class.new(Bindings.const_f_sub(@ptr, rhs))
end
-@() click to toggle source

Negate this value.

@return [ConstantReal] Instance of the same class

# File lib/rltk/cg/value.rb, line 958
def -@
        self.class.new(Bindings.const_f_neg(@ptr))
end
/(rhs) click to toggle source

Divide this value by another value.

@param [ConstantReal] rhs

@return [ConstantReal] Instance of the same class.

# File lib/rltk/cg/value.rb, line 994
def /(rhs)
        self.class.new(Bindings.const_f_div(@ptr, rhs))
end
cast(type) click to toggle source

Cast this constant real to another number type.

@param [NumberType] type Desired type to cast to.

@return [ConstantNumber] Constant number of given type.

# 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) click to toggle source

Compare this value to another value.

@see Bindings.enum_real_predicate

@param [Symbol] pred An real predicate. @param [ConstantReal] rhs Value to compare to.

@return [Int1] Value used to represent a Boolean value.

# File lib/rltk/cg/value.rb, line 1015
def cmp(pred, rhs)
        Int1.new(Bindings.const_f_cmp(pred, @ptr, rhs))
end
extend(type) click to toggle source

Extend a constant real number to a larger size.

@param [RealType] type Type to extend to.

@return [ConstantReal] This value as a real of the given type.

# 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) click to toggle source

Convert this real number into an integer.

@param [BasicIntType] type Type to convert to. @param [Boolean] signed Should the result be a signed integer or not.

@return [

# 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) click to toggle source

Truncate a constant real number to a smaller size.

@param [RealType] type Type to truncate to.

@return [ConstantReal] This value as a real of the given type.

# 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