Skip to content

float functions returns incorrect value #436

@Rithik260

Description

@Rithik260

I am encountering a issue with the expf() function from <math.h> when running c code on FPGA. The function is returning a small negative number(-4.40810382e-39) instead of the expected small positive number(0.000049) for ac0 similarly for all other variables, which suggests a problem in the floating-point library implementation. Im checking the values on gdb

Project Context & Environment
SDK: V1 branch of git

c code :
#include <stdio.h>
#include <math.h>

int main() {
float ac0 =29.020918;
float ac1 = 35.507084;
float ac2 = 31.198545;
float ac3 = 32.586067;

float result;
float sum = 0.0f;
float max_val = ac0;
if (ac1 > max_val) max_val = ac1;
if (ac2 > max_val) max_val = ac2;
if (ac3 > max_val) max_val = ac3;
ac0 = expf(ac0 - max_val);
 sum += ac0;
ac1 = expf(ac1 - max_val);
 sum += ac1;
ac2 = expf(ac2 - max_val);
 sum += ac2;
ac3 = expf(ac3 - max_val); 
sum += ac3;

return 0;

}

Make file : PULP_APP = test
PULP_APP_FC_SRCS = test.c
PULP_APP_HOST_SRCS = test.c
PULP_CFLAGS = -O0 -g
PULP_LDFLAGS += -lm # For math functions

include $(PULP_SDK_HOME)/install/rules/pulp_rt.mk

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