ARM Technical Support Knowledge Articles

_CHKFLOAT_ RETURNS STRANGE VALUES

Applies to: C251 C Compiler

Answer


Information in this article applies to:


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
"); break;
    case 1:
      printf ("result is zero
"); break;
    case 2:
      printf ("result is +INF
"); break;
    case 3:
      printf ("result is -INF
"); break;
    case 4:
      printf ("result is NaN
"); break;
    default:
      printf ("ChkFloat = %u (invalid return code)
", 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.

Article last edited on: 2005-10-20 07:46:08

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential