{"record":{"id":"a697b2891fd46e12","repo":"gleam-lang/gleam","slug":"errortype-floatwithsize","errorCode":null,"errorMessage":"ErrorType::FloatWithSize","messagePattern":"ErrorType::FloatWithSize","errorType":"validation","errorClass":"ErrorType","httpStatus":null,"severity":"error","filePath":"compiler-core/src/bit_array.rs","lineNumber":323,"sourceCode":"        size: None,\n        ..\n    } = categories\n    {\n        return err(ErrorType::UnitMustHaveSize, unit.location());\n    }\n\n    // float only 16/32/64\n    if let SegmentOptionCategories {\n        type_: Some(Float { .. }),\n        size: Some(size),\n        ..\n    } = categories\n        && let Some(abox) = size.value()\n    {\n        match abox.as_int_literal() {\n            None => (),\n            Some(value) if value == 16.into() || value == 32.into() || value == 64.into() => (),\n            _ => return err(ErrorType::FloatWithSize, size.location()),\n        }\n    }\n\n    // Segment patterns with a zero or negative constant size must be rejected,\n    // we know they will never match!\n    // A negative size is still allowed in expressions as it will just result\n    // in an empty segment.\n    if let (Some(size @ Size { value, .. }), TypeOptionsMode::Pattern) = (categories.size, mode) {\n        match value.as_int_literal() {\n            Some(n) if n <= BigInt::ZERO => {\n                return err(ErrorType::ConstantSizeNotPositive, size.location());\n            }\n            Some(_) | None => (),\n        }\n    }\n\n    Ok(categories.segment_type())\n}","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/bit_array.rs#L305-L341","documentation":"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.","triggerScenarios":"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.","commonSituations":"Assuming arbitrary float widths are allowed like integer widths; porting code that packed custom-width floats; confusing `unit` multipliers with allowed float sizes.","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."],"exampleFix":"// before\nlet a = <<x:float-size(8)>>\n// after\nlet a = <<x:float-size(32)>>","handlingStrategy":"validation","validationCode":"// Float segments allow only sizes 16, 32, 64.\nfn valid_float_size(size: Int) -> Bool {\n  size == 16 || size == 32 || size == 64\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["compiler","bit-array","value-error","gleam"],"backgroundTag":"value-out-of-range","analyzedSha":"15b07c783065c92bb016b1b74ed0995a5259850f","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}