Skip to content

pow broken for 0^(-x) #995

@Pflugshaupt

Description

@Pflugshaupt
#include <iostream>
#include "xsimd/xsimd.hpp"

int main(int argc, char *argv[]) {
  std::cout << xsimd::pow(xsimd::batch<float>(0.f), xsimd::batch<float>(-1.f)) << "\n";
  std::cout << std::pow(0.f, -1.f) << "\n";
}

produces (on sse2+ and neon)

(0, 0, 0, 0)
inf

The reason is the fix applied in #684. The result is always set to zero for input zero to work around floating point exceptions, but it should be infinity for 0^(negative number). I worked on a patch, but wasn't clever enough to do this without adding an extra comparison and an extra select(). This feels like it should be possible with one clever check somehow.

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