matrix value is -1.#QNAN

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

matrix value is -1.#QNAN

3,885 Views
dashz84
Contributor I
hi,

in the same .c file, i have a main function and another function called get_dv.

inside main, i initialize an array by saying
double dphidx[]={
  0.0, -1.0, -94.02, -1.0, 0.0, 1.0, 94.02, 1.0, 0.0, -1.0, -102.6, -1.0, 0.0, 1.0, 102.6, 1.0
  }; //16 element array

however, when i enter the debugger, the first 3 elements of the array appears to be -1.#QNAN, while the rest of the array is correct. i get the same result if I initialize the array element by element.

Then inside get_dv i initialize another array dphidx2[] similar to dphidx[] from main, yet this time, every single element is -1.#QNAN.

i selected float32 and double32 from the set up menu. can someone please help me fix this?

Thanks
Labels (1)
Tags (1)
0 Kudos
8 Replies

1,072 Views
Lundin
Senior Contributor IV
Sounds like either a stack error or a pointer bug to me. Impossible to tell the cause without the full code.

1,072 Views
stanish
NXP Employee
NXP Employee
Hello dashz84,

Could you possibly specify:
1) which version of CodeWarrior are you using?
2) which ANSI lib are you using within your project?
3) could you possibly try to define the arrays as global variables? are they initialized correctly?
4) does the problem occure in full chip simulator?

Stanish
0 Kudos

1,072 Views
dashz84
Contributor I
after trying a few different things, here's what I have found out.

The elements inside an array of type double, will appear correctly only, if total variable declarations do not exceed 122 bits of data. This is using float 32, double 32, regardless of using Mb or Ml for the compiler library size option.

i've tried a brand new project with nothing but array declarations in the main function, likewise, if total array size exceeds 122 bits, then the arrays that were declared as 'double' will take the hit and display -1.#QNAN, while the ones declared as 'int' or 'unsigned int' do not get affected.

hopefully this tells u a bit more about my problem.

thank you
0 Kudos

1,072 Views
dashz84
Contributor I
hi stanish,

this is what i'm doing ->

1) I'm using CW v4.7 (with update patch 4.71) on vista
2) the library file is ansibf.lib
3) i've tried initializing the array as a global variable, but it still doesn' twork, all the values were incorrect.
   i've also tried initializing the array with int values inside a function, the results i got were mostly -1's with only correct values for the last 6 elements.
4) the problem persists in Full chip simulation as well.

please help
thank you
0 Kudos

1,072 Views
CompilerGuru
NXP Employee
NXP Employee
The problem you have is very probably a memory setup problem.
Basically a float/double of "-1.#QNAN" means that all bits are set, the memory at this place just contains 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF.
So the question is why does the memory location you store the doubles in contain invalid data,
and that depends on what kind of variable dphidx is. Is it a local? Global? Where is it placed?
What is the address of the array? Sounds like it is not in valid RAM.

If it is a local, make sure you have enough stack. If it is a global, make sure the memory in the prm file is correctly defined.

Daniel
0 Kudos

1,072 Views
dashz84
Contributor I
Hi Daniel,

I think u r right about the array not being in valid RAM space.

I have tried defining it both as a global and local array, the result is the same -> as long as the dphidx as well as the rest of the variable declarations do not exceed 122 bits, then I am able to dfine them correctly.

So, how do I make sure that there is enough stack for my array?
0 Kudos

1,072 Views
dashz84
Contributor I
after a closer examination of CW, and going through the 'bean inspector for CPU' menu, i realized that I needed to change the Stack Size manually there.

Previously the stack size was automatically set to be 0080H, but I changed it to 1000H, and then everything was working fine. There was no more -1.#QNAN and all the arrays were correctly initialized.
0 Kudos

1,072 Views
Lundin
Senior Contributor IV
I would advise against declaring such large arrays on the stack. Put it in a separate memory segment. How to do this is CPU specific, but at least on HC(S)08 and HC(S)12 versions of CW, you edit the prm file. Create a separate segment in the RAM with exactly the size you need for your array, then allocate the array at file scope (global).
0 Kudos