c++standard-library

Mathematical special function not found despite, supposedly, being defined in cmath


I need to use the logarithmic integral function which is defined in the cmath header. Unfortunately, I get an error: no member named 'expint' in namespace 'std' when I try to compile it. To reproduce this error you just need to try to compile this file.

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
  
int main()
{
    std::cout << "Ei(0) = " << std::expint(0) << '\n'
              << "Ei(1) = " << std::expint(1) << '\n'
              << "Gompertz constant = " << -std::exp(1) * std::expint(-1) << '\n';
}

I tried to compile this file specifying the std library: c++17, gnu++17, gnu++20, gnu++2b and got the same error every time. I am on a M1 Mac with compiler

Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

What is the problem? Why isn't this function defined on cmath?


Solution

  • std::expint and family was introduced in C++17 and per the cppreference compiler support page only GGC 7+ (libstdc++), MSVS 19.14+ and Embarcadero 10.3+ support them currently.

    You will need to use homebrew and get GCC or Clang with libstdc++ or get MSVS somehow if you want to use these functions right now.