Board index » delphi » Eliminating NAN Fields in a tables calculated field

Eliminating NAN Fields in a tables calculated field

Hi there !!!

I am using calculated fields on a Query Table within Delphi 5 Pro.  Within the calculated fields, I get NAN fields when I really want displayed is the number Zero on divisible calculations.

I have used a try on EDivByZero and EZeroDivide to try to catch the error.  Ideally, when this error happens, I want the field to say Zero, but whichever Exception Error I use, I still see a NAN displayed instead of Zero.  The two numbers I am trying to divide (numerator and denominator) are both integer numbers.  The resulting variable is of a real type.  The resulting variable can be changed to single, double or extended if it would help aleviate this NAN error I keep getting.  Because of the NANs that pops up, it messes up any kind of calculations (sumation, average, Min, Max, or Count) I do on that column.

Also, when doing calculations in querys, how does Delphi handle calculations when a field is blank ?  Is Delphi smart enough to assume that the blank field(s) is zero and still carry out the calculation ?

Any thoughts or insights ?

Thanks much to anyone that can help !!!

 

Re:Eliminating NAN Fields in a tables calculated field


"John Herbster \(TeamB\)" <herb-sci at novus-tele.net> wrote:
Quote
>"Jedi Knight Disco Mike" <DiscoM...@Hotmail.Com> wrote
>> I am using calculated fields on a Query Table within Delphi 5 Pro.
>> Within the calculated fields, I get NAN fields when I really want
>> displayed is the number Zero on divisible calculations.

>I don't understand.  Are you allowing your code to attempt division
>by zero?  If so, why not just check for division before the divide?

>> I have used a try on EDivByZero and EZeroDivide to try to catch
>> the error.  Ideally, when this error happens, I want the field to say
>> Zero,

>Do you mean that you want to set the result to zero on exceptions?

>> but whichever Exception Error I use, I still see a NAN displayed
>> instead of Zero.  The two numbers I am trying to divide
>> (numerator and denominator) are both integer numbers.
>> The resulting variable is of a real type.

>> The resulting variable can be changed to single, double or extended
>> if it would help alleviate this NAN error I keep getting.

>From basic algebra, a divide by zero does not give a valid number,
>you must handle it before you do the divide or catch it after the divide
>attempt.

>Unless somebody's code has been tampering with the FPU control
>word, any attempt to divide by zero should give an exception.  Does
>it?

>> Also, when doing calculations in queries, how does Delphi handle
>> calculations when a field is blank ?
>> Is Delphi smart enough to assume that the blank field(s) is zero ...

>It may very well assume that a blank field is zero,
>but I would not call that *smart*.  It can lead to problems.
>Regards, JohnH

Yes... I am allowing my code to divide by zero in a try except statement:
try
  Result:=A/B
except
  on EDivByZero (or EZeroDiv)
     Result:=0;
end;

but when B is zero, it is not handling the except statement.  It returns a NAN in the Result value.  All the code is writen by me, it is not inherited code.  None of my code makes any alterations to the FPU or CPU.  Maybe I have a setting off in the Delphi environment ?

Any ideas ?

Thanks much for all your input !

Other Threads