Re: Draft 2 is now available

From: David Miller <David.L.Miller_at_.....>
Date: Wed Jan 16 2008 - 13:04:21 PST
Resend - first go has not come through.

Hi Paul,

yes sorry, I missed making this correction.

However I am not sure the below conditions work for all cases.

If a > 0 and b < 0, then we also need to do the ceil().

So I think the condition should be:

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

I should also make a mention that an error is raised if b == 0. I think we
should mention this simply because digital makes the point that b == 0 results
in x being returned.

Here is the rewrite of the section, if you are happy with it, I will send it
through to Stuart to include in draft 3. I also used a ternary as the condition
is not so bad now with just the check of a/b < 0.

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

It shall be an error to pass zero (0) as the second argument to the modulus
operator.

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

a % b = ((a/b) < 0) ? (a - ceil(a,b)*b) : (a - floor(a,b)*b);

"

Cheers...
Dave

Paul Floyd wrote:
> 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

-- 
=====================================
-- David Miller
-- Design Technology (Austin)
-- Freescale Semiconductor
-- Ph : 512 996-7377 Fax: x7755
=====================================


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

This archive was generated by hypermail 2.1.8 : Wed Jan 16 2008 - 13:27:43 PST