Skip to content

Crash or strange result when printing f32 #112

@usbalbin

Description

@usbalbin

Not sure if this is the place for this kind of issue...

During #93 (see comment)I discovered that the following code snippet seems to crash on ESP32-S3 and likely ESP32(have not tested the last example on ESP32 yet):

fn main() -> anyhow::Result<()> {
    esp_idf_sys::link_patches();

    let v = 16.0;
    println!("f32 literal is={v}");

    let v = f32::from(16_u16);
    println!("Converting the number seems to work");
    println!("from u16 to f32 is={v}"); // <--- Boom
    loop {}
}

Also note in the log from where I first discovered the problem that there is weird output for several of the "duty" lines before the crash. From what I can tell the actual number printed is important. 16 seems to be the smallest integer >= 0 that when converted to f32 causes a crash. Some of the smaller values only causes weird output.

Somehow I can not seem to reproduce the problem by using a f32 literal(not the exact same value due to floating point magic?)

Compiling in release mode and using IDF v4.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions