Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 02 Apr 2026 20:09:56 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 294214] clang builtin functions break libm
Message-ID:  <bug-294214-227@https.bugs.freebsd.org/bugzilla/>

index | next in thread | raw e-mail

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=294214

            Bug ID: 294214
           Summary: clang builtin functions break libm
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: kargl@FreeBSD.org

It has been brought to my attention that the use of some
clang builtin functions break libm.  Consider,

#include <math.h>
#include <stdio.h>

int
main(void)
{
   double f, x, y;

   x = 0.;
   y = copysign(x, -1.);
   printf("fmax(% lf % lf) = % lf\n", x, x, fmax(x,x));
   printf("fmax(% lf % lf) = % lf\n", x, y, fmax(x,y));
   printf("fmax(% lf % lf) = % lf\n", y, x, fmax(y,x));

   return (0);
}

% cc -o z fmax.c -lm && ./z
fmax( 0.000000  0.000000) =  0.000000
fmax( 0.000000 -0.000000) =  0.000000
fmax(-0.000000  0.000000) = -0.000000  <--- this is wrong

% cc -o z fmax.c -lm -fno-builtin && ./z
fmax( 0.000000  0.000000) =  0.000000
fmax( 0.000000 -0.000000) =  0.000000
fmax(-0.000000  0.000000) =  0.000000

% gcc15 -o z fmax.c -lm && ./z
fmax( 0.000000  0.000000) =  0.000000
fmax( 0.000000 -0.000000) =  0.000000
fmax(-0.000000  0.000000) =  0.000000  <--- this is correct

% -o z fmax.c -lm -fno-builtin && ./z
fmax( 0.000000  0.000000) =  0.000000
fmax( 0.000000 -0.000000) =  0.000000
fmax(-0.000000  0.000000) =  0.000000

The FreeBSD documentation has

% man fmax
...
DESCRIPTION
   The fmax(), fmaxf(), and fmaxl() functions return the larger of x and y,
   and likewise, the fmin(), fminf(), and fminl() functions return the
   smaller of x and y.  They treat +0.0 as being larger than -0.0.

-- 
You are receiving this mail because:
You are the assignee for the bug.

home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-294214-227>