Closed mrk-its closed 9 months ago
As workaround non-saturating cast may be performed with https://doc.rust-lang.org/std/primitive.f32.html#method.to_int_unchecked
This apparently lowered to the max and min family of functions in libm; we will need an implementation for those.
Does this involve adding the functions to common/include/math.h
, and add a new corresponding math.cpp
file to produce a static library m
? Also, are comparison operators already available for floats?
Does this involve adding the functions to
common/include/math.h
, and add a new correspondingmath.cpp
file to produce a static librarym
? Also, are comparison operators already available for floats?
Yes to all.
Here's a preliminary implementation. Not entirely sure if this should be split into it's own static library with add_platform_library(m, ...)
?.
https://github.com/llvm-mos/llvm-mos-sdk/compare/main...mlund:llvm-mos-sdk:fminmax?expand=1
Here's a preliminary implementation. Not entirely sure if this should be split into it's own static library with
add_platform_library(m, ...)
?. https://github.com/llvm-mos/llvm-mos-sdk/compare/main...mlund:llvm-mos-sdk:fminmax?expand=1
Separate libm provides no benefit to modern static-linking-only toolchain; best not to follow that particular convention. We should provide an empty stub libm though to make sure -lm
is always legal.
You will need to account for NaN: min and max have to return the other argument if one is NaN.
In RUST cast from float to int (with
as
keyword) is saturating operation: https://doc.rust-lang.org/reference/expressions/operator-expr.html#numeric-castand for now it generates following error: