From 5cf7e26acf2d1dcf119de9aadd13f9f7756e9a7a Mon Sep 17 00:00:00 2001 From: Cary R Date: Fri, 9 Jan 2009 09:43:02 -0800 Subject: [PATCH] Finish real modulus in verireal. Verireal had hooks for this, but had an assert(0). This patch replaces the assert(0) with assert(gn_icarus_misc_flag) and then used fmod() to calculate the modulus. It is the callers responsibility to verify and report a message to the user if the current state should not support real modulus. --- eval_tree.cc | 2 +- verireal.cc | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/eval_tree.cc b/eval_tree.cc index 1cde0c882..5b8110a39 100644 --- a/eval_tree.cc +++ b/eval_tree.cc @@ -836,7 +836,7 @@ NetExpr* NetEBDiv::eval_tree_real_() // Since this could/may be called early we don't want to // leak functionality. if (!gn_icarus_misc_flag) return 0; - res = new NetECReal(verireal(fmod(lval.as_double(), rval.as_double()))); + res = new NetECReal(lval % rval); break; } ivl_assert(*this, res); diff --git a/verireal.cc b/verireal.cc index 3e188796e..78827facd 100644 --- a/verireal.cc +++ b/verireal.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2004 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2009 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -18,6 +18,7 @@ */ # include "config.h" +# include "compiler.h" # include "verireal.h" # include "verinum.h" @@ -140,14 +141,20 @@ verireal operator/ (const verireal&l, const verinum&r) verireal operator% (const verireal&l, const verireal&r) { verireal res; - assert(0); + // Modulus of a real value is not supported by the standard, + // but we support it as an extension. Assert that we are in + // the correct state before doing the operation. + assert(gn_icarus_misc_flag); + res.value_ = fmod(l.value_, r.value_); return res; } verireal operator% (const verireal&l, const verinum&r) { verireal res; - assert(0); + // See above. + assert(gn_icarus_misc_flag); + res.value_ = fmod(l.value_, (double)r.as_long()); return res; } @@ -170,4 +177,3 @@ ostream& operator<< (ostream&out, const verireal&v) out << v.value_; return out; } -