Re: Draft 2 is now available

From: Paul Floyd <Paul_Floyd_at_.....>
Date: Wed Jan 16 2008 - 02:16:58 PST
David Miller wrote:

> Draft 2 of LRM 2.3 is now available:
> http://www.eda-stds.org/verilog-ams/htmlpages/public-docs/VAMS_v2.3-Draft2.pdf 
>


Hi

I've just had a quick look at this draft.

The description of modulus hasn't  changed, and I think that it is 
incorrect. I sent a mail about this a while back. I've changed it a bit, 
and here it is again.

On Page 65, it states that

"The modulus operator, for example y % z, gives the remainder when the 
first operand is
divided by the second, and thus is zero (0) when z divides y exactly. 
The result of a
modulus operation takes the sign of the first operand.

For the case of the modulus operator where either argument is real, the 
operation
performed is

a % b = a - floor(a/b)*b;"

This is contradictory in the case where a is negative and b is positive. 
The problem is that floor rounds down, not toward zero (which is 
rounding up for negative numbers). For example, if a is -10.0 and b is 
3.75, then we have

-10.0 - floor(-10.0/3.75)*3.75
= -10.0 - floor(-2.67)*3.75
= -10.0 - -3*3.75
= -10.0 + 11.25
= +1.25

which does not have the same sign as a.

If the description is changed to

if (a < 0.0 && b > 0.0) then
  a % b = a - ceil(a/b)*b;
else
  a % b = a - floor(a/b)*b;

Using the same example figures

-10.0 - ceil(-10.0/3.75)*3.75
= -10.0 - ceil(-2.67)*3.75
= -10.0 - -2*3.75
= -10.0 + 7.5
= -2.5

(It's possible to use the ternary conditional operator as well, but it 
makes for an unweildy expression).

Regards
Paul Floyd
-- 
Dr. Paul Floyd
Mentor Graphics Corporation


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Wed Jan 16 02:17:18 2008

This archive was generated by hypermail 2.1.8 : Wed Jan 16 2008 - 02:17:36 PST