View unanswered posts | View active topics It is currently Wed Jun 07, 2023 8:41 pm

← Back to the Calcudoku puzzle page

Reply to topic  [ 11 posts ]  Go to page Previous  1, 2
 mod and negative numbers 
Author Message

Posted on: Sat Sep 29, 2018 9:37 pm

Posts: 917
Location: Ukraine
Joined: Tue Mar 01, 2016 10:03 pm
Post Re: mod and negative numbers
pnm wrote:
paulv66 wrote:
Patrick, can you clarify please? Also, is zero allowed as the denominator in a mod cell? For example, could you give 2 mod 0 as a solution for a cage with value mod 2? Or will a mod cage with zero in it always have to have value zero?

No, for a divisor zero the modulo operation is not defined, so it's not allowed.

(edit: I'll double-check this too, I've seen a definition where "x mod 0 = x", so maybe that would work)

When the divisor is negative, the result is "implementation dependent" as they say
(so it depends on the programming language used). In my case, the language is C++:
here the remainder has the same sign as the dividend.

But a puzzle generator script is written in Perl, which uses the convention
that the remainder has the same sign as the divisor..

I need to check if this causes any problems for the puzzle generation, will keep you posted.

Hi Patrick

Did you get a chance to look into this? I only have four puzzles left to solve in your latest book, but I'm going round in circles on these four puzzles. One thing they all have in common is that they include negative numbers (or at least one negative number) and zero and they all include the mod function. I'm unsure how the mod function is supposed to work with negative values and zero.

Jpoos clarified how it works where there is a negative value in the numerator and a positive value in the denominator and his explanation makes sense and is consistent with how ithe mod function works with two positive numbers. What is unclear is whether it is permitted to have a negative denominator in a mod function and, if so, how is the value calculated?

It's also unclear whether you can have zero in the denominator (as discussed earlier in one of your responses to this thread) and, if so, how is the value calculated (e.g. is x mod 0 = x)?

It would also be helpful to have some clarity around how the bitwise functions deal with negative numbers. In an earlier post, you said that minus 1 is effectively treated as 7, although you admitted that this is not entirely logical. Further clarification would be most welcome.


Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ]  Go to page Previous  1, 2

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
All forum contents © Patrick Min, and by the post authors.

Forum software phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.