From d8bdea11c5dec5b57333cadebad423e6d9191fd1 Mon Sep 17 00:00:00 2001 From: Cary R Date: Fri, 16 Dec 2011 19:02:52 -0800 Subject: [PATCH] To reduce error divide by an integer vs multiple by a fraction. This same change was done in the vpi directory. This patch fixes the issues in the libveriuser directory. This fixed a fail in the vpi timescale test under MinGW. --- libveriuser/getsimtime.c | 8 ++++---- libveriuser/veriusertfs.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libveriuser/getsimtime.c b/libveriuser/getsimtime.c index e016af08e..716480f4d 100644 --- a/libveriuser/getsimtime.c +++ b/libveriuser/getsimtime.c @@ -36,8 +36,8 @@ scale(int high, int low, void*obj) { scaled = high; scaled = (scaled << 32) | low; - scaled *= pow(10, vpi_get(vpiTimePrecision,0) - - vpi_get(vpiTimeUnit,obj ? (vpiHandle)obj : hand)); + scaled /= pow(10, vpi_get(vpiTimeUnit,obj ? (vpiHandle)obj : hand) - + vpi_get(vpiTimePrecision,0)); return scaled; } @@ -129,8 +129,8 @@ void tf_scale_realdelay(void*obj, double real, double *areal) { vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0)); - *areal = real * pow(10, vpi_get(vpiTimePrecision, 0) - - vpi_get(vpiTimeUnit, hand)); + *areal = real / pow(10, vpi_get(vpiTimeUnit, hand) - + vpi_get(vpiTimePrecision, 0)); } void tf_unscale_realdelay(void*obj, double real, double *areal) diff --git a/libveriuser/veriusertfs.c b/libveriuser/veriusertfs.c index 740b80fd2..dc8d350df 100644 --- a/libveriuser/veriusertfs.c +++ b/libveriuser/veriusertfs.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2010 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2002-2011 Michael Ruff (mruff at chiaro.com) * Michael Runyan (mrunyan at chiaro.com) * * This source code is free software; you can redistribute it @@ -402,7 +402,7 @@ PLI_INT32 tf_isetrealdelay(double dly, void*obj) /* Scale delay to SimTime */ ivl_u64_t delay = ((dly - * pow(10, tf_gettimeprecision() - tf_gettimeunit())) + / pow(10, tf_gettimeunit() - tf_gettimeprecision())) + 0.5); ti.high = delay >> 32 & 0xffffffff; ti.low = delay & 0xffffffff;