| |||||
Technical Support Support Resources
Product Information | C251: _CHKFLOAT_ RETURNS STRANGE VALUESInformation in this article applies to:
SYMPTOMThe _chkfloat_ library routine does not detect floating-point numbers with the -INF value. The following program demonstrates this issue:
#include <reg251s.h>
#include <intrins.h>
#include <math.h>
#include <stdio.h> /* for printf */
void tst_chkfloat (float f1) {
unsigned x;
x = _chkfloat_(f1);
switch (x) {
case 0:
printf ("result is a number\n"); break;
case 1:
printf ("result is zero\n"); break;
case 2:
printf ("result is +INF\n"); break;
case 3:
printf ("result is -INF\n"); break;
case 4:
printf ("result is NaN\n"); break;
default:
printf ("ChkFloat = %u (invalid return code)\n", x);
break;
}
}
void main (void)
{
float f2, f3;
SCON = 0x50;
TMOD |= 0x20;
TH1 = 221;
TR1 = 1;
TI = 1;
f2 = 9.9e30;
f3 = 8.8e30;
tst_chkfloat(f2*f3);
f2 = 9.9e30;
f3 = -8.8e30;
tst_chkfloat(f2*f3);
tst_chkfloat(sqrt(-1.1));
tst_chkfloat(0.0);
f2 = 9.9e30;
f3 = 8.8e30;
tst_chkfloat(f2+f3);
while(1);
}
CAUSEThis issue is caused by a problem in the _chkfloat_ library routine. RESOLUTIONThe _chkfloat_ routine has been corrected in the attached library. This will be integrated into the next C251 product release. ATTACHED FILESRequest the files attached to this knowledgebase article. Last Reviewed: Thursday, October 20, 2005 | ||||
| |||||