davidmakovoz
asked on
erratic NaN's
I am getting NaN's evaluating the following statement
costWithDelete = RowVectorTwo[i - 1] + m_DeleteCost;
The left hand side values are regular values and i-1 is not out of bounds.
The most strangest thing is that it happens completely randomly.
Any ideas what can cause this bevavior?
Thanks,
David
costWithDelete = RowVectorTwo[i - 1] + m_DeleteCost;
The left hand side values are regular values and i-1 is not out of bounds.
The most strangest thing is that it happens completely randomly.
Any ideas what can cause this bevavior?
Thanks,
David
ASKER
They are all floats and when I put
Single.IsNaN(costWithInser t)
afterwards it catches it.
Moreover if I do the following
costWithDelete = RowVectorTwo[i - 1] + m_DeleteCost;
while (Single.IsNaN(costWithDele te))
{
Console.WriteLine("{0} {1} {2}", costWithDelete, RowVectorTwo[i - 1], m_DeleteCost);
costWithDelete = RowVectorTwo[i - 1] + m_DeleteCost;
}
the program prints out a NaN once or twice and then proceeds happily
Single.IsNaN(costWithInser
afterwards it catches it.
Moreover if I do the following
costWithDelete = RowVectorTwo[i - 1] + m_DeleteCost;
while (Single.IsNaN(costWithDele
{
Console.WriteLine("{0} {1} {2}", costWithDelete, RowVectorTwo[i - 1], m_DeleteCost);
costWithDelete = RowVectorTwo[i - 1] + m_DeleteCost;
}
the program prints out a NaN once or twice and then proceeds happily
@vo1d
NaN is "Not A Number".
@davidmakovoz
Can you show us some code and how costWithDelete, m_DeleteCost and RowVectorTwo are declared?
Fernando
NaN is "Not A Number".
@davidmakovoz
Can you show us some code and how costWithDelete, m_DeleteCost and RowVectorTwo are declared?
Fernando
Hi davidmakovoz;
Microsoft states that: "Floating-point operations return NaN to signal that that result of the operation is undefined. For example, dividing 0.0 by 0.0 results in NaN."
So look for a operation that may cause this to happen.
Fernando
Microsoft states that: "Floating-point operations return NaN to signal that that result of the operation is undefined. For example, dividing 0.0 by 0.0 results in NaN."
So look for a operation that may cause this to happen.
Fernando
ASKER
private float m_EditCost, m_DeleteCost, m_InsertCost, m_RecallPrecisionRelativeW eight;
float[] RowVectorOne = new float[rows];
float[] RowVectorTwo = new float[rows];
float costWithInsert;
float costWithDelete;
float costWithEdit;
The problem is that this line is a piece of a fairly big project.
I have been trying to simplify it to locate the cause
but so far unsuccesfully.
In my experience this kind of problem is caused
by the memory being messed up.
And it can be done by any part of the program
seemingly unrelated to the one where the NaN shows up.
I wonder if there is a way in VS debugger to set up
memory access checking. I know such functionality
exists in Sun's debugger "workshop".
Also I was under the impression that C# does
very rigorous array bounds checking and such
would ocurr the whole program would crash.
float[] RowVectorOne = new float[rows];
float[] RowVectorTwo = new float[rows];
float costWithInsert;
float costWithDelete;
float costWithEdit;
The problem is that this line is a piece of a fairly big project.
I have been trying to simplify it to locate the cause
but so far unsuccesfully.
In my experience this kind of problem is caused
by the memory being messed up.
And it can be done by any part of the program
seemingly unrelated to the one where the NaN shows up.
I wonder if there is a way in VS debugger to set up
memory access checking. I know such functionality
exists in Sun's debugger "workshop".
Also I was under the impression that C# does
very rigorous array bounds checking and such
would ocurr the whole program would crash.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
of what type is evaluating, RowVectorTwo, DeleteCost ?