This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 686b515b959fa13e5b3d488e5e899cf1ef2fe446 Author: chenchaokai <[email protected]> AuthorDate: Tue Aug 19 11:19:07 2025 +0800 libc/time: Fix the precision loss in difftime(). difftime() converted both time_t operands to double before subtracting them. When time_t is 64-bit, values above 2^53 are not exactly representable in a double, so the difference of two nearby times could be wrong. Subtract in time_t first and convert only the result. Signed-off-by: chenchaokai <[email protected]> Signed-off-by: ganjing <[email protected]> --- libs/libc/time/lib_difftime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/libc/time/lib_difftime.c b/libs/libc/time/lib_difftime.c index f158b5501ed..3eac62a73e4 100644 --- a/libs/libc/time/lib_difftime.c +++ b/libs/libc/time/lib_difftime.c @@ -48,7 +48,7 @@ #ifdef CONFIG_HAVE_DOUBLE double difftime(time_t time1, time_t time0) { - return (double)time1 - (double)time0; + return (double)(time1 - time0); } #elif defined(CONFIG_HAVE_FLOAT) float difftime(time_t time1, time_t time0)
