Topic: Question about sign of remainder op (1 of 10), Read 73 times
Conf: VEDIT Sales and Info
From: Deleted User
Date: Saturday, October 22, 2005 03:19 PM

Hello:

I do not understand the sign of the remainder when using Vedit's remainder op (%)

Relevant formulas:

quotient = dividend / divisor
(* truncate quotient toward zero *)

remainder = dividend % divisor

quotient * divisor + remainder = dividend

sign(remainder) = sign(dividend)
0 <= ABS(remainder) < ABS(divisor)

==============================================================
The following is the example from p. 25, N. Wirth, "Algorithms & Data Structures", (c) 1988 N. Wirth,
Prentice-Hall.

Vedit returns the following when executed in a Command Mode window:

31 / 10 = 3
31 % 10 = 1

-31 / 10 = -3
-31 % 10 = 1 (* Wirth has -1 *)

31 / -10 = -3
31 % -10 = 1

-31 / -10 = 3
-31 % -10 = 1 (* Wirth has -1 *)
===============================================================
The Vedit quotient from the division operation is consistent with Wirth's "Eulerian integer arithmetic"
but the remainder operation does not yield the correct signs, although the magnitude is correct.

The result of Vedit's remainder operator (%) (and Vedit's internal value Remainder) always returns a positive remainder, regardless of the signs of the divisor and dividend.

The Vedit 6.0 Macro Language Reference Manual, Version 6.03, p. 73 further states that the remainder has
"...the same sign as the quotient," but Vedit is also not consistent with this behavior.

The x86 instruction for signed division (IDIV) is defined as follows on page 139 of "AMD x86-64 Architecture Programmer's Manual Vol. 3"

"The instruction truncates non-integral results [quotients] toward 0. The sign of the remainder is always the same as the sign of the dividend, and the absolute value of the remainder is is less than the absolute value of the divisor."


The Vedit remainder is apparently inconsistent with "ANSI C/C99" and the x86 IDIV instruction and also it's
own definition.

Help.

Carl Glassberg

 


Topic: Re: Question about sign of remainder op (2 of 10), Read 77 times
Conf: VEDIT Sales and Info
From: Ted Green
Date: Monday, October 24, 2005 12:14 PM

At 03:19 PM 10/22/2005, you wrote:

>The Vedit 6.0 Macro Language Reference Manual, Version 6.03, p. 73 further states that the remainder has
>"...the same sign as the quotient," but Vedit is also not consistent with this behavior.

Carl:

I can confirm that VEDIT is not returning the correct sign. I will add it
to our bug list, but cannot give it a high priority.

Ted.


Ted.
-------------------------------------------------------------------------
Ted Green (ted@...) Greenview Data, Inc.
Web: www.... Fax: 734-996-1308 PO Box 1586, Ann Arbor, MI 48106
Tel: (734) 996-1300 Desk: 734-369-3550 VEDIT - Text/Data/Binary Editor
-------------------------------------------------------------------------
www.SpamStopsHere.com ranked #1 in accuracy by Network Computing Magazine

 


Topic: Question about sign of remainder op (3 of 10), Read 58 times
Conf: VEDIT Sales and Info
From: Peter Rejto
Date: Wednesday, August 25, 2010 12:21 PM

On 10/22/2005 3:19:02 PM, Deleted User wrote:
>Hello:
>
>I do not understand the sign
>of the remainder when using
>Vedit's remainder op (%)
>
>Relevant formulas:
>
>quotient = dividend / divisor
>(* truncate quotient toward
>zero *)
>
>remainder = dividend % divisor
>
>quotient * divisor + remainder
>= dividend
>
>sign(remainder) =
>sign(dividend)
>0 <= ABS(remainder) <
>ABS(divisor)
>
>==============================
>==============================
>==
>The following is the example
>from p. 25, N. Wirth,
>"Algorithms & Data
>Structures", (c) 1988 N.
>Wirth,
>Prentice-Hall.
>
>Vedit returns the following
>when executed in a Command
>Mode window:
>
> 31 / 10 = 3
> 31 % 10 = 1
>
>-31 / 10 = -3
>-31 % 10 = 1 (* Wirth has -1
>*)
>
> 31 / -10 = -3
>31 % -10 = 1
>
>-31 / -10 = 3
>-31 % -10 = 1 (* Wirth has -1
>*)
>==============================
>==============================
>===
>The Vedit quotient from the
>division operation is
>consistent with Wirth's
>"Eulerian integer arithmetic"
>but the remainder operation
>does not yield the correct
>signs, although the magnitude
>is correct.
>
>The result of Vedit's
>remainder operator (%) (and
>Vedit's internal value
>Remainder) always returns a
>positive remainder, regardless
>of the signs of the divisor
>and dividend.
>
>The Vedit 6.0 Macro Language
>Reference Manual, Version
>6.03, p. 73 further states
>that the remainder has
>"...the same sign as the
>quotient," but Vedit is also
>not consistent with this
>behavior.
>
>The x86 instruction for signed
>division (IDIV) is defined as
>follows on page 139 of "AMD
>x86-64 Architecture
>Programmer's Manual Vol. 3"
>
>"The instruction truncates
>non-integral results
>[quotients] toward 0. The sign
>of the remainder is always the
>same as the sign of the
>dividend, and the absolute
>value of the remainder is is
>less than the absolute value
>of the divisor."
>
>
>The Vedit remainder is
>apparently inconsistent with
>"ANSI C/C99" and the x86 IDIV
>instruction and also it's
>own definition.
>
>Help.
>
>Carl Glassberg


Hi,

I tried to work out another example: Specifically, I have
tried Carl's second example with 3 in place of 31 and 8 in place of 10. This led to

#1=3%8
#1

Vedit replied with 3.


Do I understand it correctly ? 3%8 means the integer part of the remainder of 3 divided by 8. I get 0.


Thanks,

-peter

 


Topic: Re: Question about sign of remainder op (4 of 10), Read 62 times
Conf: VEDIT Sales and Info
From: Christian Ziemski
Date: Wednesday, August 25, 2010 02:49 PM

On 25.08.2010 18:22 vedit-info Listmanager wrote:
> From: "peter rejto"
>
> #1=3%8
> #1
>
> Vedit replied with 3.
>
>
> Do I understand it correctly ? 3%8 means the integer part of the
> remainder of 3 divided by 8. I get 0.

'3' is correct.

0 % 8 = 0
1 % 8 = 1
2 % 8 = 2
3 % 8 = 3
4 % 8 = 4
5 % 8 = 5
6 % 8 = 6
7 % 8 = 7
8 % 8 = 0
9 % 8 = 1
10 % 8 = 2
11 % 8 = 3
12 % 8 = 4
13 % 8 = 5
14 % 8 = 6
...

Christian

 


Topic: Re: Question about sign of remainder op (5 of 10), Read 66 times
Conf: VEDIT Sales and Info
From: Peter Rejto
Date: Wednesday, August 25, 2010 11:28 PM

On 8/25/2010 2:49:21 PM, Christian Ziemski wrote:
>On 25.08.2010 18:22 vedit-info
>Listmanager wrote:
>> From: "peter rejto"
>>
>> #1=3%8
>> #1
>>
>> Vedit replied with 3.
>>
>>
>> Do I understand it correctly ? 3%8 means the integer part of the
>> remainder of 3 divided by 8. I get 0.
>
>'3' is correct.


Thanks Christian,

I was wrong. 3%8 does not mean the integer part of the
remainder. It means the smallest positive remainder.
How could I miss it ?


-peter


>
>0 % 8 = 0
>1 % 8 = 1
>2 % 8 = 2
>3 % 8 = 3
>4 % 8 = 4
>5 % 8 = 5
>6 % 8 = 6
>7 % 8 = 7
>8 % 8 = 0
>9 % 8 = 1
>10 % 8 = 2
>11 % 8 = 3
>12 % 8 = 4
>13 % 8 = 5
>14 % 8 = 6
>...
>
>Christian

 


Topic: Re: Question about sign of remainder op (6 of 10), Read 57 times
Conf: VEDIT Sales and Info
From: Peter Rejto
Date: Saturday, August 28, 2010 12:33 AM

On 8/25/2010 2:49:21 PM, Christian Ziemski wrote:
>On 25.08.2010 18:22 vedit-info
>Listmanager wrote:
>> From: "peter rejto"
>>
>> #1=3%8
>> #1
>>
>> Vedit replied with 3.
>>
>>
>> Do I understand it correctly ? 3%8 means the integer part of the
>> remainder of 3 divided by 8. I get 0.
>
>'3' is correct.


Christian,


I am re reading your email. Of course, that I was after was the decimal equivalent of the fraction 3/8.


I am also re reading Carl's email. Certainly the Wirth reference is a nice one. I was glad to find it on Wikipedia. I was not so glad to find that all it says about the individual chapters are the titles. I take that for my problem only Chapter 3, Recursive Algorithms are needed.

So, I went ahead and improvised. Here is my pseudo code:

Let a and b be two given positive integers. (In other words, we will have to figure out the sign of the quotient later. I take this is Ted's philosophy)


Step 1. Define the successive remainders recursively by


r_0=a/b,
r_1=10*r_0%b,
and so on. That is to say,
r_(n+1)=10r_n%b, for n=0,1,2,3....




Step 2. Define the successive digits of the quotient by,

d_0=a/b,
d_1=10r_0/b
and so on. That is to say,
d_(n+1)= 10r_n/ for n=0,1,2,3...


Step 3. Put the digits together to get the actual quotient.

Specifically, set q=d_0. d_1 d_2.....



If this sounds reasonable to you, I would appreciate your suggestions about turning my pseudo code into exact Vedit codes.


Thanks as always.


-peter

 


Topic: Re: Question about sign of remainder op (7 of 10), Read 53 times
Conf: VEDIT Sales and Info
From: Christian Ziemski
Date: Saturday, August 28, 2010 04:16 PM

On 28.08.2010 06:33 vedit-info Listmanager wrote:
> From: "peter rejto"
>
> r_0=a/b,
> r_1=10*r_0%b,
> and so on. That is to say,
> r_(n+1)=10r_n%b, for n=0,1,2,3....

Fascinating.


Peter:

I'm not a mathematician like you.

So I'm afraid I can't help here.

And please don't forget:
VEDIT is an editor, not an all purpose (esp. math) programming language!


Christian

 


Topic: Re: Question about sign of remainder op (8 of 10), Read 50 times
Conf: VEDIT Sales and Info
From: Peter Rejto
Date: Sunday, August 29, 2010 11:53 AM

On 8/28/2010 4:16:23 PM, Christian Ziemski wrote:
>On 28.08.2010 06:33 vedit-info
>Listmanager wrote:
>> From: "peter rejto"
>>
>> r_0=a/b,
>> r_1=10*r_0%b,
>> and so on. That is to say,
>> r_(n+1)=10r_n%b, for n=0,1,2,3....
>
>Fascinating.
>
>
>Peter:
>
>I'm not a mathematician like you.

>Christian


Christian,

I am also an avid cyclist and I had a very simple problem in mind:

Shimano gives the diameter of their rear axle nut as 9.5 mm.
The old B(ritish) S(tandard) C(ycle) gives this diameter as 3/8 inches.

So, I wanted to know whether or not the two values are equivalent or not.

The key step in answering this question is to convert 3/8 into decimals.

I believe, I can do this from the Vedit keyboard.
Here it is:

Get into Command Mode and type:

Step 1.

3/8

Vedit responds with ...0.

Step 2.

3%8

Vedit responds with ... 3.


Step 3.

3*10

Step 4:

30%8

Vedit responds with ... 6.

Step 5:

Put the pieces together.

This gives 0.3


Repeating steps 3 and 4 gives 7
Another repetition of steps 3 and 4 gives 5.


Putting all this together gives the final answer:


3/8=0.375


-peter

 


Topic: Re: Question about sign of remainder op (9 of 10), Read 76 times
Conf: VEDIT Sales and Info
From: Christian Ziemski
Date: Sunday, August 29, 2010 12:47 PM

On 29.08.2010 17:54 vedit-info Listmanager wrote:
> From: "peter rejto"
>
> Shimano gives the diameter of their rear axle nut as 9.5 mm.
> [...]
> The key step in answering this question is to convert 3/8 into decimals.
>
> I believe, I can do this from the Vedit keyboard.
> 3/8
> 3%8
> [...]
>
> 3/8=0.375

Wow, now I learned something about the interrelation of Shimano and
Vedit. ;-)

Having to calculate that with an integer calculator like Vedit I would
simply do it this way:

3 * 1000 / 8
gives 375

Divide 375 by 1000 again by moving the decimal point to the left 3 times.
Gives 0.375

(That is how I did my Floating Point Vedit macros.)


Christian

 


Topic: Re: Question about sign of remainder op (10 of 10), Read 27 times
Conf: VEDIT Sales and Info
From: Ian Binnie
Date: Sunday, August 29, 2010 10:04 PM

On 8/29/2010 11:53:51 AM, peter rejto wrote:
>Shimano gives the diameter of their rear
>axle nut as 9.5 mm.
>The old B(ritish) S(tandard) C(ycle)
>gives this diameter as 3/8 inches.
>
>So, I wanted to know whether or not the
>two values are equivalent or not.
>
>The key step in answering this question
>is to convert 3/8 into decimals.

Wouldn't it be easier to use a calculator (or mental arithmetic).

PS You need to check your other assumptions. Many quoted dimensions are conventions, not absolute sizes.
E.g. many years ago Australia converted to metric.
You can no longer buy a 1/4" bolt, but the 6mm bolts still fit into pre metric 1/4" nuts.