Keil Logo

C51: _CHKFLOAT_ RETURNS STRANGE VALUES


Information in this article applies to:

  • C51 Version 7.10 and Earlier

SYMPTOM

The _chkfloat_ library routine does not detect floating-point numbers with the -INF value. The following program demonstrates this issue:

#include <reg51.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);
}

CAUSE

This issue is caused by a problem in the _chkfloat_ library routine.

RESOLUTION

The _chkfloat_ routine is corrected in the C51 V7.20 (and later) update. You may download the latest updates from the Keil Website.

MORE INFORMATION

SEE ALSO

Last Reviewed: Thursday, October 20, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.