Keil Logo

C251: _CHKFLOAT_ RETURNS STRANGE VALUES


Information in this article applies to:

  • C251 Version 3.60 and Earlier

SYMPTOM

The _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);
}

CAUSE

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

RESOLUTION

The _chkfloat_ routine has been corrected in the attached library. This will be integrated into the next C251 product release.

ATTACHED FILES

Request the files attached to this knowledgebase article.

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.