gleam-lang/gleam · error · ErrorType
ErrorType::FloatWithSize
Error message
ErrorType::FloatWithSize
What it means
Float bit array segments may only have a size of exactly 16, 32, or 64 bits. When a float segment has a `size` option whose value evaluates to an integer literal other than 16/32/64, `type_options` raises `FloatWithSize` at the size option's location. Non-constant size expressions cannot be checked here and pass this check.
Solutions
- Change the size to 16, 32, or 64, e.g. `<<x:float-size(32)>>`.
- Omit the size option to get the default 64-bit float: `<<x:float>>`.
- If a non-standard width is required, store the value as an integer with the desired bit width instead.
Example fix
// before let a = <<x:float-size(8)>> // after let a = <<x:float-size(32)>>
Defensive patterns
Strategy: validation
Validate before calling
// Float segments allow only sizes 16, 32, 64.
fn valid_float_size(size: Int) -> Bool {
size == 16 || size == 32 || size == 64
} Prevention
- Only use 16, 32, or 64 as float segment sizes.
- Omit size entirely for the default 64-bit float.
- Use integer segments for custom bit widths.
When it happens
Trigger: Writing `<<x:float-size(8)>>` or `<<0.0:float-size(128)>>` — any constant size other than 16/32/64 on a `float` segment, in an expression or a pattern.
Common situations: Assuming arbitrary float widths are allowed like integer widths; porting code that packed custom-width floats; confusing `unit` multipliers with allowed float sizes.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- ErrorType::ConstantSizeNotPositive
- ErrorType::SignednessUsedOnNonInt
- ErrorType::TypeDoesNotAllowSize
- ErrorType::TypeDoesNotAllowUnit
- ErrorType::UnitMustHaveSize
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/a697b2891fd46e12.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-core/src/bit_array.rs:323
size: None,
..
} = categories
{
return err(ErrorType::UnitMustHaveSize, unit.location());
}
// float only 16/32/64
if let SegmentOptionCategories {
type_: Some(Float { .. }),
size: Some(size),
..
} = categories
&& let Some(abox) = size.value()
{
match abox.as_int_literal() {
None => (),
Some(value) if value == 16.into() || value == 32.into() || value == 64.into() => (),
_ => return err(ErrorType::FloatWithSize, size.location()),
}
}
// Segment patterns with a zero or negative constant size must be rejected,
// we know they will never match!
// A negative size is still allowed in expressions as it will just result
// in an empty segment.
if let (Some(size @ Size { value, .. }), TypeOptionsMode::Pattern) = (categories.size, mode) {
match value.as_int_literal() {
Some(n) if n <= BigInt::ZERO => {
return err(ErrorType::ConstantSizeNotPositive, size.location());
}
Some(_) | None => (),
}
}
Ok(categories.segment_type())
}View on GitHub (pinned to 15b07c7830)