Skip to content

NEC math: vectorized powf precision #271

@raver119

Description

@raver119
#include <stdio.h>
#include <cassert>

int main(){

    const int nSize = 2048;
    const float eps = 1e-5;
    float x[nSize];
    float res[nSize];
    float y[nSize];
    for(int i = 0; i < nSize; i++){
        x[i] = 3.0;
        y[i] = 10.0;
    }
    for(int i = 0; i < nSize; i++){
        res[i] = powf(x[i], y[i]);
    }

    int j;
    for(j = 0; j < nSize; j++){
        auto diff = fabs(res[j] - 59049.000000f);
        if(diff > eps){
            printf("Res: %f; diff: %f; \n", res[j], diff);
            break;
        }
    }

 return 0;
}

GCC result:
59049.000000.

NCC result:
Res: 59048.996094; diff: 0.003906;

NCC result doesn't change behaviour with -fno-fast-math compiler option. With bigger operands - delta between gcc and ncc grows.

Scalar powf result perfectly matches gcc result.

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