Calcudoku puzzle forumhttps://www.calcudoku.org/forum/ mod and negative numbershttps://www.calcudoku.org/forum/viewtopic.php?f=3&t=1089 Page 2 of 2

 Author: paulv66 [ Sat Sep 29, 2018 9:37 pm ] Post subject: 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 conventionthat 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 PatrickDid 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.ThanksPaul

 Page 2 of 2 All times are UTC + 1 hour [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/