#include #include "libm.h" #if __riscv_flen >= 64 double round(double x) { if (((asuint64(x) >> 52) & 0x7ff) >= 52+0x3ff) return x; double tmp; long long n; __asm__ ("fcvt.l.d %0, %1, rmm" : "=r"(n) : "f"(x)); __asm__ ("fcvt.d.l %0, %1" : "=f"(tmp) : "r"(n)); // the sign bit is only copied to handle round(-0.0) __asm__ ("fsgnj.d %0, %1, %2" : "=f"(x) : "f"(tmp), "f"(x)); return x; } #else #include "../round.c" #endif