473,884 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MOD operator

A statement of the form (m mod n) uses the sign of the first operand (m) as
the sign of the result. I've ecnountered an issue where I need it to use
the sign of the second operand. Here's what it looks like now:

-363 mod -60 = -3
-363 mod 60 = -3
363 mod -60 = 3

Anyone have any ideas? Thanks.
Nov 21 '05 #1
3 11511
for m mod n with sign of m ignored and sign of n used, try
abs(m mod n)*sign(n)
abs and sign are in system.math.

"Michael C#" wrote:
A statement of the form (m mod n) uses the sign of the first operand (m) as
the sign of the result. I've ecnountered an issue where I need it to use
the sign of the second operand. Here's what it looks like now:

-363 mod -60 = -3
-363 mod 60 = -3
363 mod -60 = 3

Anyone have any ideas? Thanks.

Nov 21 '05 #2
Thanks for the reply. I actually have an even worse problem with mod at
this point, and the sign is just one part of it. As far as I can tell, the
Mod function should be the amount by which a number exceeds the largest
integer multiple of the divisor that is not greater than that number. This
definition leads to some inconsistencies I'll have to sort through in order
to figure this out. The problem is that Mod in VB truncates toward zero,
which is throwing these calculations wayyyy off. I need a formula that
truncates toward -infinity.

"AMercer" <AM*****@discus sions.microsoft .com> wrote in message
news:3D******** *************** ***********@mic rosoft.com...
for m mod n with sign of m ignored and sign of n used, try
abs(m mod n)*sign(n)
abs and sign are in system.math.

"Michael C#" wrote:
A statement of the form (m mod n) uses the sign of the first operand (m)
as
the sign of the result. I've ecnountered an issue where I need it to use
the sign of the second operand. Here's what it looks like now:

-363 mod -60 = -3
-363 mod 60 = -3
363 mod -60 = 3

Anyone have any ideas? Thanks.

Nov 21 '05 #3
Thanks for the help. I found a proper Modulo formula that uses the Floor
function to return a correct Modulo, and not just the "Remainder of
Division".

"AMercer" <AM*****@discus sions.microsoft .com> wrote in message
news:3D******** *************** ***********@mic rosoft.com...
for m mod n with sign of m ignored and sign of n used, try
abs(m mod n)*sign(n)
abs and sign are in system.math.

"Michael C#" wrote:
A statement of the form (m mod n) uses the sign of the first operand (m)
as
the sign of the result. I've ecnountered an issue where I need it to use
the sign of the second operand. Here's what it looks like now:

-363 mod -60 = -3
-363 mod 60 = -3
363 mod -60 = 3

Anyone have any ideas? Thanks.

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
8038
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so something like this: 1) e = (a, b, c, d); // concatenate a,b,c,d into e 2) (a, b, c, d) = e; // get the bits of e into a,b,c, and d For example, in the second case, assume that a,b,c,d represent 2-bit integers, and e represents an 8-bit...
1
3885
by: joesoap | last post by:
Hi can anybody please tell me what is wrong with my ostream operator??? this is the output i get using the 3 attached files. this is the output after i run assignment2 -joesoap #include "BitString.h"
5
3814
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more complex operator, I get stuck. Here's a brief description what I want to do. I want to simulate a matrix (2D array) from a 1D array. so what I have so far is something like this: class Matrix
0
1840
by: Martin Magnusson | last post by:
I have defined a number of custom stream buffers with corresponding in and out streams for IO operations in my program, such as IO::output, IO::warning and IO::debug. Now, the debug stream should be disabled in a release build, and to do that efficiently, I suppose I need to overload the << operator. My current implementation of the stream in release mode is posted below. Everything works fine for POD type like bool and int, but the...
3
2964
by: Sensei | last post by:
Hi. I have a problem with a C++ code I can't resolve, or better, I can't see what the problem should be! Here's an excerpt of the incriminated code: === bspalgo.cpp // THAT'S THE BAD FUNCTION!!
6
4435
by: YUY0x7 | last post by:
Hi, I am having a bit of trouble with a specialization of operator<<. Here goes: class MyStream { }; template <typename T> MyStream& operator<<(MyStream& lhs, T const &)
3
18844
by: gugdias | last post by:
I'm coding a simple matrix class, which is resulting in the following error when compiling with g++ 3.4.2 (mingw-special): * declaration of `operator/' as non-function * expected `;' before '<' token <snip> --------------------------------------------------- template <class T> class matriz;
5
2300
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason my C++.NET 2.0 textbook does not have one. I tried to build one using the format as taught in my regular C++ book, but I keep getting compiler errors. Some errors claim (contrary to my book) that you cannot use a static function, that you must...
8
2495
by: valerij | last post by:
Yes, hi How to write "operator +" and "operator =" functions in a class with a defined constructor? The following code demonstrates that I don't really understand how to do it... I think it has something to do with the compiler calling the destructor twice. Could someone point out where I go wrong? P.S.: The error it gives is "Debug Assertion Failure ....." (at run time) P.P.S: Everything else works just fine (without the use of...
3
3292
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj, obj2 ;
0
9953
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7137
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5808
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4231
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3242
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.