Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Mod operator

How come the Mod operator can return negative values? I've always
wondered why.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Mod operator

well, what is there to wonder in that.
-3 Mod 2 will return -1
and that is perfect

- manges

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Mod operator



mangesh_yadav < wrote:
well, what is there to wonder in that.
-3 Mod 2 will return -1
and that is perfect

- mangesh


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Mod operator

Is that standard in all major programming languages?


mangesh_yadav < wrote:
well, what is there to wonder in that.
-3 Mod 2 will return -1
and that is perfect

- mangesh


---
Message posted from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Mod operator

It has to be.

- Manges

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Mod operator

You seem to be getting into the universal definition paradigm. VBA defines
how the MOD operator works. Excel has a MOD function and it works
differently - but its operation is defined in help. Mathematics may have
another definition of how MOD works or rather what modulus/modulo is. You
can't assume that a programming function will work the way your math teacher
defined a math operation. You have to look at the documentation.

as an illustrative point, one would think that addition would be pretty
straightforward, but then you run into limitations in the IEEE
implementation of a double . . .

Each language that has a standard defines their own implementation. Those
that don't have a recognized standard define it in their documentation.
There is no universal standard (that I am aware of) that you seem to imply.

http://support.microsoft.com/default...78&Product=xlw
MOD Function and Mod Operator Return Different Values

http://support.microsoft.com/default...71&Product=xlw
XL2000: MOD Function and Mod Operator Return Different Values

--
Regards,
Tom Ogilvy

"R Avery" wrote in message
...
Is that standard in all major programming languages?


mangesh_yadav < wrote:
well, what is there to wonder in that.
-3 Mod 2 will return -1
and that is perfect

- mangesh


---
Message posted from http://www.ExcelForum.com/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Mod operator

Ok. Point taken. Thanks, Tom.

Tom Ogilvy wrote:

You seem to be getting into the universal definition paradigm. VBA defines
how the MOD operator works. Excel has a MOD function and it works
differently - but its operation is defined in help. Mathematics may have
another definition of how MOD works or rather what modulus/modulo is. You
can't assume that a programming function will work the way your math teacher
defined a math operation. You have to look at the documentation.

as an illustrative point, one would think that addition would be pretty
straightforward, but then you run into limitations in the IEEE
implementation of a double . . .

Each language that has a standard defines their own implementation. Those
that don't have a recognized standard define it in their documentation.
There is no universal standard (that I am aware of) that you seem to imply.

http://support.microsoft.com/default...78&Product=xlw
MOD Function and Mod Operator Return Different Values

http://support.microsoft.com/default...71&Product=xlw
XL2000: MOD Function and Mod Operator Return Different Values

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Mod operator

Some implementations of MOD work differently when the arguments have different
signs. The worksheet function uses the definition that the modulus is always
positive, i.e. =MOD(-10,3) yields -4 with a remainder of 2. OTOH, in VBA,
definition that's used is probably what you division in grade school: -10
divided by +3 is -3 with a remainder of -1.


On Wed, 01 Sep 2004 10:08:40 -0400, R Avery wrote:

How come the Mod operator can return negative values? I've always
wondered why.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
about & operator [email protected] Excel Discussion (Misc queries) 2 December 12th 08 04:44 PM
Operator for Contains Leanne M (Aussie) Excel Worksheet Functions 2 October 21st 08 11:01 AM
Operator kittycris Excel Worksheet Functions 3 January 11th 07 01:36 AM
IN operator Suzanne Excel Worksheet Functions 4 May 10th 06 06:28 PM
Need help with the Like Operator DennisE Excel Programming 3 April 27th 04 11:47 PM


All times are GMT +1. The time now is 03:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"