class RCGTK::ConstantReal
All real constants inherit from this class.
@abstract
Public Class Methods
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/rcgtk/value.rb, line 943 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
Modulo this value by another value.
@param [ConstantReal] rhs
@return [ConstantReal] Instance of the same class.
# File lib/rcgtk/value.rb, line 1004 def %(rhs) self.class.new(Bindings.const_f_remm(@ptr, rhs)) end
Multiply this value with another value.
@param [ConstantReal] rhs
@return [ConstantReal] Instance of the same class.
# File lib/rcgtk/value.rb, line 986 def *(rhs) self.class.new(Bindings.const_f_mul(@ptr, rhs)) end
Add this value with another value.
@param [ConstantReal] rhs
@return [ConstantReal] Instance of the same class.
# File lib/rcgtk/value.rb, line 968 def +(rhs) self.class.new(Bindings.const_f_add(@ptr, rhs)) end
Subtract a value from this value.
@param [ConstantReal] rhs
@return [ConstantReal] Instance of the same class.
# File lib/rcgtk/value.rb, line 977 def -(rhs) self.class.new(Bindings.const_f_sub(@ptr, rhs)) end
Negate this value.
@return [ConstantReal] Instance of the same class
# File lib/rcgtk/value.rb, line 959 def -@ self.class.new(Bindings.const_f_neg(@ptr)) end
Divide this value by another value.
@param [ConstantReal] rhs
@return [ConstantReal] Instance of the same class.
# File lib/rcgtk/value.rb, line 995 def /(rhs) self.class.new(Bindings.const_f_div(@ptr, rhs)) end
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/rcgtk/value.rb, line 1025 def cast(type) type.value_class.new(Bindings.const_fp_cast(@ptr, check_cg_type(type, NumberType))) end
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/rcgtk/value.rb, line 1016 def cmp(pred, rhs) Int1.new(Bindings.const_f_cmp(pred, @ptr, rhs)) end
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/rcgtk/value.rb, line 1044 def extend(type) type.value_class.new(Bindings.const_fp_ext(@ptr, check_cg_type(type, RealType))) end
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 [ConstantNumber] Constant
number of given type
# File lib/rcgtk/value.rb, line 1035 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 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/rcgtk/value.rb, line 1053 def truncate(type) type.value_class.new(Bindings.const_fp_trunc(@ptr, check_cg_type(type, RealType))) end