# Cypress Developer CommunityTM

## PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Summary: 16 Replies, Latest post by Bob Marlowe on 24 Oct 2016 02:58 AM PDT
User
5 posts

#include <project.h>
#include "math.h"

int main()
{
int  st_speed=30; // m/s
int x_axis = 10; // in  meter

float g = 9.807; // in  m/s^2

CyGlobalIntEnable; /* Enable global interrupts. */

calc_Angle_x = (1/2*asin(x_axis*g/st_speed*st_speed))*((180.0)/3.14);

for(;;)
{

why does calc_Angle_x return nan(0x8000000000000) and what nan means?

It supposed to return 3.129462438 degree

Attachments:
User
9301 posts

NAN means "Not a Number" and indicates the result of an invalid operation as division by zero. asin acceps an argument between 1 and -1. In your case the argument is 10 which is not allowed. Try to use parentheses.

Bob

User
5 posts

where do you think I have to put parentheses

calc_Angle_x = (1/2*asin((x_axis*g)/(st_speed*st_speed))*((180.0)/3.14);

User
9301 posts

This differs from your previous post. Now you have used parentheses.

Bob

User
5 posts

by using calculator I get the right sulution. the problems comes in psoc. it doesn't help to put parentheses in.

NB: the values has to be the one you see in project.

User
9301 posts

calc_Angle_x = (1/2*asin(x_axis*g/st_speed*st_speed)*((180.0)/3.141592));

and you should have

calc_Angle_x = (1/2*asin(x_axis*g/(st_speed*st_speed))*((180.0)/3.141592));

or

calc_Angle_x = (1/2*asin(x_axis*g/st_speed/st_speed)*((180.0)/3.141592));

What makes things easier would be to calculate the argument as

double Argument;

Argument = x_axis*g/(st_speed*st_speed);

calc_Angle_x = (1/2*asin(Argument)*((180.0)/3.141592));

By the way: What is the goal of your project?

Bob

User
5 posts

Thank you Bob

Goal of my project is to compare the measure of calc_Angle_x with angle x from accelerometer.

if those to angle are equal. green led has to turn on if there are not, green led has to turn off and red led turn on.

User
18 posts

Hi MR Robertniyo.could u runing adxl345 with i2c?because i cant solved this problem!!!

can u give me your project for learning how i can to do?

tanks...

User
9301 posts

Bob

User
18 posts

dear bob i dont want to flooding the forum.tankyou for your explanation but it is not helpful for me.so i want to check my code project with a correct project code to find mistake.

User
9301 posts

Post your actual schematics (sketch, no photos) and project bundle, tell us where you got stuck. Did you follow all hints I gave you when I explained I2C handling?

Bob