Permalink
Browse files

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.
  • Loading branch information...
1 parent cba8b42 commit 5cf7e26acf2d1dcf119de9aadd13f9f7756e9a7a @caryr caryr committed with Jan 9, 2009
Showing with 11 additions and 5 deletions.
  1. +1 −1 eval_tree.cc
  2. +10 −4 verireal.cc
View
2 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);
View
14 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;
}
-

0 comments on commit 5cf7e26

Please sign in to comment.