Convert Inf and NaN values properly.
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
/*************************************************************************\
|
||||
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
|
||||
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
|
||||
* National Laboratory.
|
||||
* Copyright (c) 2002 The Regents of the University of California, as
|
||||
* Operator of Los Alamos National Laboratory.
|
||||
* EPICS BASE Versions 3.13.7
|
||||
* and higher are distributed subject to a Software License Agreement found
|
||||
* EPICS BASE is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
/*epicsConvert.c*/
|
||||
|
||||
#include <math.h>
|
||||
#include <epicsMath.h>
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
|
||||
@@ -21,15 +20,23 @@ epicsShareFunc float epicsConvertDoubleToFloat(double value)
|
||||
{
|
||||
float rtnvalue;
|
||||
|
||||
if(value==0.0) {
|
||||
return(0.0);
|
||||
if (value == 0.0) {
|
||||
rtnvalue = 0.0;
|
||||
} else if (!finite(value)) {
|
||||
rtnvalue = (float)value;
|
||||
} else {
|
||||
double abs = fabs(value);
|
||||
|
||||
if(abs>=FLT_MAX) {
|
||||
if(value>0.0) rtnvalue = FLT_MAX; else rtnvalue = -FLT_MAX;
|
||||
} else if(abs<=FLT_MIN) {
|
||||
if(value>0.0) rtnvalue = FLT_MIN; else rtnvalue = -FLT_MIN;
|
||||
if (abs >= FLT_MAX) {
|
||||
if (value > 0.0)
|
||||
rtnvalue = FLT_MAX;
|
||||
else
|
||||
rtnvalue = -FLT_MAX;
|
||||
} else if(abs <= FLT_MIN) {
|
||||
if (value > 0.0)
|
||||
rtnvalue = FLT_MIN;
|
||||
else
|
||||
rtnvalue = -FLT_MIN;
|
||||
} else {
|
||||
rtnvalue = (float)value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user