#include #if __riscv_flen >= 32 float roundf(float x) { if (!isfinite(x) || fabsf(x) >= 0x1p23) return x; float tmp; long n; __asm__ ("fcvt.w.s %0, %1, rmm" : "=r"(n) : "f"(x)); __asm__ ("fcvt.s.w %0, %1" : "=f"(tmp) : "r"(n)); // the sign bit is only copied to handle round(-0.0) __asm__ ("fsgnj.s %0, %1, %2" : "=f"(x) : "f"(tmp), "f"(x)); return x; } #else #include "../roundf.c" #endif