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

            Bug ID: 284905
           Summary: __builtin_powf produces incorrect result on FreeBSD
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: misc
          Assignee: b...@freebsd.org
          Reporter: y...@freebsd.org

Reposting from https://github.com/llvm/llvm-project/issues/127841:

Not sure if this is a clang bug or FreeBSD bug, but consider:

#include <cmath>
#include <iostream>

int main()
{
  if (std::pow(10.0f, 11.0f) == __builtin_powf(10.0f, 11.0f))
    std::cout << "Equals __builtin_powf\n";
  else
    std::cout << "Unequal to __builtin_powf\n";

  if (std::pow(10.0f, 11.0f) == __builtin_powif(10.0f, 11))
    std::cout << "Equals __builtin_powif\n";
  else
    std::cout << "Unequal to __builtin_powif\n";

  std::cout << "32-bit float difference: " << (std::pow(10.0f, 11.0f) - 1e11f)
<< std::endl;
  std::cout << "64-bit double difference: " << (std::pow(10.0f, 11.0f) - 1e11)
<< std::endl;
}

On my x86_64 FreeBSD VM, this gives:

builder@ganesha:~ $ uname -a
FreeBSD ganesha 14.2-RELEASE-p1 FreeBSD 14.2-RELEASE-p1 GENERIC amd64

builder@ganesha:~ $ clang++ --version
FreeBSD clang version 18.1.6 (https://github.com/llvm/llvm-project.git
llvmorg-18.1.6-0-g1118c2e05e67)
Target: x86_64-unknown-freebsd14.2
Thread model: posix
InstalledDir: /usr/bin

builder@ganesha:~ $ clang++ test.cxx

builder@ganesha:~ $ ./a.out
Equals __builtin_powf
Unequal to __builtin_powif
32-bit float difference: 8192
64-bit double difference: 6144

Whereas on macOS and OpenBSD (on the same hardware) it gives:

Equals __builtin_powf
Equals __builtin_powif
32-bit float difference: 0
64-bit double difference: -2048

Same result on x86_64 with clang 19.1 on godbolt:

https://godbolt.org/z/sceY9da3b

Only the FreeBSD case is different from everyone else.

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

Reply via email to