pub struct FloatType<'ctx> { /* private fields */ }
Expand description

A FloatType is the type of a floating point constant or variable.

Implementations§

Create FloatType from LLVMTypeRef

Safety

Undefined behavior, if referenced type isn’t float type

Creates a FunctionType with this FloatType for its return type.

Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let fn_type = f32_type.fn_type(&[], false);

Creates an ArrayType with this FloatType for its element type.

Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_array_type = f32_type.array_type(3);

assert_eq!(f32_array_type.len(), 3);
assert_eq!(f32_array_type.get_element_type().into_float_type(), f32_type);

Creates a VectorType with this FloatType for its element type.

Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_vector_type = f32_type.vec_type(3);

assert_eq!(f32_vector_type.get_size(), 3);
assert_eq!(f32_vector_type.get_element_type().into_float_type(), f32_type);

Creates a FloatValue repesenting a constant value of this FloatType. It will be automatically assigned this FloatType’s Context.

Example
use inkwell::context::Context;

// Local Context
let context = Context::create();
let f32_type = context.f32_type();
let f32_value = f32_type.const_float(42.);

Create a FloatValue from a string. LLVM provides no error handling here, so this may produce unexpected results and should not be relied upon for validation.

Example
use inkwell::context::Context;
use inkwell::values::AnyValue;

let context = Context::create();
let f64_type = context.f64_type();
let f64_val = f64_type.const_float_from_string("3.6");

assert_eq!(f64_val.print_to_string().to_string(), "double 3.600000e+00");

let f64_val = f64_type.const_float_from_string("3.");

assert_eq!(f64_val.print_to_string().to_string(), "double 3.000000e+00");

let f64_val = f64_type.const_float_from_string("3");

assert_eq!(f64_val.print_to_string().to_string(), "double 3.000000e+00");

let f64_val = f64_type.const_float_from_string("");

assert_eq!(f64_val.print_to_string().to_string(), "double 0.000000e+00");

let f64_val = f64_type.const_float_from_string("3.asd");

assert_eq!(f64_val.print_to_string().to_string(), "double 0x7FF0000000000000");

Creates a constant zero value of this FloatType.

Example
use inkwell::context::Context;
use inkwell::values::AnyValue;

let context = Context::create();
let f32_type = context.f32_type();
let f32_zero = f32_type.const_zero();

assert_eq!(f32_zero.print_to_string().to_string(), "float 0.000000e+00");

Gets the size of this FloatType. Value may vary depending on the target architecture.

Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_type_size = f32_type.size_of();

Gets the alignment of this FloatType. Value may vary depending on the target architecture.

Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_type_alignment = f32_type.get_alignment();

Gets a reference to the Context this FloatType was created in.

Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();

assert_eq!(f32_type.get_context(), context);

Creates a PointerType with this FloatType for its element type.

Example
use inkwell::context::Context;
use inkwell::AddressSpace;

let context = Context::create();
let f32_type = context.f32_type();
let f32_ptr_type = f32_type.ptr_type(AddressSpace::default());

#[cfg(not(feature = "llvm15-0"))]
assert_eq!(f32_ptr_type.get_element_type().into_float_type(), f32_type);

Print the definition of a FloatType to LLVMString.

Creates an undefined instance of a FloatType.

Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_undef = f32_type.get_undef();

assert!(f32_undef.is_undef());

Creates a GenericValue for use with ExecutionEngines.

Creates a constant ArrayValue.

Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_val = f32_type.const_float(0.);
let f32_val2 = f32_type.const_float(2.);
let f32_array = f32_type.const_array(&[f32_val, f32_val2]);

assert!(f32_array.is_const());

Trait Implementations§

Returns an AnyTypeEnum that represents the current type.
Prints the definition of a Type to a LLVMString.
Returns a BasicTypeEnum that represents the current type.
Create a FunctionType with this BasicType as its return type. Read more
Determines whether or not this BasicType is sized or not. For example, opaque structs are unsized. Read more
Gets the size of this BasicType. Value may vary depending on the target architecture. Read more
Create an ArrayType with this BasicType as its elements. Read more
Create a PointerType that points to this BasicType. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
The value instance of a float or float vector type.
The type for float to int or float vector to int vector conversions.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.