Skip to content

pow returns incorrect values for 0 as exponent or 1 as base #1458

Open

Description

@Ivorforce

I'd expect xsimd to behave like C99 F.9.4.4 / IEEE 754, but there are some failure cases.

MRP:

#include <xsimd/xsimd.hpp>

#include <cmath>
#include <iostream>
#include <limits>

int main()
{
    const double nan = std::numeric_limits<double>::quiet_NaN();
    const double inf = std::numeric_limits<double>::infinity();
    const double cases[][2] = { { 0., 0. }, { 2., 0. }, { nan, 0. }, { inf, 0. }, { -inf, -0. }, { 1., nan }, { 1., inf }, { -1., inf }, { -1., -inf } };
    for (const auto& c : cases)
    {
        const xsimd::batch<double> x(c[0]), y(c[1]);
        std::cout << "pow(" << c[0] << ", " << c[1] << "): xsimd " << xsimd::pow(x, y).get(0)
                  << ", std " << std::pow(c[0], c[1]) << "\n";
    }
}

Output (master 4c44d61, across all arm64 NEON, x86-64 SSE2 and AVX2+FMA):

pow(0, 0): xsimd 0, std 1
pow(2, 0): xsimd 1, std 1
pow(nan, 0): xsimd nan, std 1
pow(inf, 0): xsimd nan, std 1
pow(-inf, -0): xsimd nan, std 1
pow(1, nan): xsimd nan, std 1
pow(1, inf): xsimd nan, std 1
pow(-1, inf): xsimd nan, std 1
pow(-1, -inf): xsimd nan, std 1

Activity

  1. changed the title [-]`pow` returns incorrect values for `0` as exponent or `0` as base[/-] [+]`pow` returns incorrect values for `0` as exponent or `1` as base[/+] on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions