Fix $rtoi to correctly convert NaN and +/- infinity
This commit is contained in:
parent
095cedb305
commit
7b07fca285
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2003-2010 Michael Ruff (mruff at chiaro.com)
|
* Copyright (c) 2003-2013 Michael Ruff (mruff at chiaro.com)
|
||||||
*
|
*
|
||||||
* This source code is free software; you can redistribute it
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* and/or modify it in source code form under the terms of the GNU
|
||||||
|
|
@ -158,7 +158,7 @@ static PLI_INT32 sys_itor_calltf(ICARUS_VPI_CONST PLI_BYTE8*user)
|
||||||
vpi_get_value(arg, &value);
|
vpi_get_value(arg, &value);
|
||||||
|
|
||||||
/* convert */
|
/* convert */
|
||||||
value.value.real = (PLI_INT32)value.value.integer;
|
value.value.real = value.value.integer;
|
||||||
value.format = vpiRealVal;
|
value.format = vpiRealVal;
|
||||||
|
|
||||||
/* return converted value */
|
/* return converted value */
|
||||||
|
|
@ -203,17 +203,22 @@ static PLI_INT32 sys_rtoi_calltf(ICARUS_VPI_CONST PLI_BYTE8*user)
|
||||||
vpiHandle arg = (vpiHandle) vpi_get_userdata(callh);
|
vpiHandle arg = (vpiHandle) vpi_get_userdata(callh);
|
||||||
s_vpi_value value;
|
s_vpi_value value;
|
||||||
static struct t_vpi_vecval res;
|
static struct t_vpi_vecval res;
|
||||||
|
double val;
|
||||||
|
|
||||||
/* get value */
|
/* get value */
|
||||||
value.format = vpiRealVal;
|
value.format = vpiRealVal;
|
||||||
vpi_get_value(arg, &value);
|
vpi_get_value(arg, &value);
|
||||||
|
|
||||||
/* convert */
|
/* If the value is NaN or +/- infinity then return 'bx */
|
||||||
if (value.value.real >= 0.0)
|
val = value.value.real;
|
||||||
res.aval = (unsigned)value.value.real;
|
if (val != val || (val && (val == 0.5*val))) {
|
||||||
else
|
res.aval = ~(PLI_INT32)0;
|
||||||
res.aval = - (unsigned)-value.value.real;
|
res.bval = ~(PLI_INT32)0;
|
||||||
res.bval = 0;
|
} else {
|
||||||
|
if (val >= 0.0) res.aval = (PLI_UINT32) val;
|
||||||
|
else res.aval = - (PLI_UINT32) -val;
|
||||||
|
res.bval = 0;
|
||||||
|
}
|
||||||
|
|
||||||
value.format = vpiVectorVal;
|
value.format = vpiVectorVal;
|
||||||
value.value.vector = &res;
|
value.value.vector = &res;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue