modulus

Find multiples of a number in PHP

Hay i need help. I want to find all muliples of a number in PHP. I'm using something like this if($count != 20 ) to work out if $count is not equal to 20. but i also need this script to check if $count is not equal to 20,40,60,80,100,120,140,160 etc. Any ideas? I think i need to use the modulus symbol (%), but i don't know. Thank...

need to print 5 column list in alpha order, vertically

Have a webpage that will be viewed by mainly IE users, so CSS3 is out of the question. I want it to list like: A D G B E H C F I Here is the function that currently lists like: A B C D E F G H I function listPhoneExtensions($group,$group_title) { $adldap = new adLDAP(); $group_membership = $adldap->group_members(strtouppe...

Random number with modulus in Objective C

I have a very basic random number function which generates a random number from a range; ie: // The random is seeded earlier on in the applicationDidFinishLaunching() function -(NSUInteger)makeRandomNumber:(NSUInteger)minNumber to:(NSUInteger)maxNumber { //NSUInteger i = (NSUInteger)( (random() / (double)RAND_MAX) * y); NSUInteger i...

Strange bug in this time calculation script?!

Basically this script will subtract StartTime from EndTime, using a jQuery plugin the html form is populated with Start and End Time in the format HH:MM, an input field is populated with the result, it works except for one issue: If Start Time is between 08:00 and 09:59 it just returns strange results - results are 10 hours off to be pr...

Leading zero when subtracting one time from another javascript

function setValue() { var startTime = document.getElementById('ToilA'); var endTime = document.getElementById('EndHours'); startTime = startTime.value.split(":"); var startHour = parseInt(startTime[0], 10); var startMinutes = parseInt(startTime[1], 10); endTime = endTime.value.split(":"); var endHour = parseInt(endTime[0], 10); va...

Modulus with doubles in Java

How do you deal with Java's weird behaviour with the modulus operator when using doubles? For example, you would expect the result of 3.9 - (3.9 % 0.1) to be 3.9 (and indeed, Google says I'm not going crazy), but when I run it in Java I get 3.8000000000000003. I understand this is a result of how Java stores and processes doubles, but ...

PHP % operator, what result should be returned?

Hi, $djs_all_num = mysql_num_rows($djs_all_db); while($djs_all = mysql_fetch_array( $djs_all_db )) { if ($djs_all_num % "2") { With my if () statement, this should halve the amount of rows, and so in the else further on it should display the rest. Is this correct? ...

Weird mod behavior in Obj. C

I have the following code: NSInteger index1 = (stop.timeIndex - 1); //This will be -1 index1 = index1 % [stop.schedule count]; // [stop.schedule count] = 33 So I have the expression -1 % 33. This should give me 32, but is instead giving me 3... I've double checked the values in the debugger. Does anyone have any ideas? ...

C - floor of double moduls integer

I need to do the following equation floor(e%100000) where e is a double. I know mod only accepts int values, how do I go about achieving this same result? Thanks ...

Modulus operator changes

$5.6/4 in C++03 states- "If both operands are nonnegative then the remainder is nonnegative;if not, the sign of the remainder is implementation-defined74). where Note 74 is According to work underway toward the revision of ISO C, the preferred algorithm for integer division follows the rules defined inthe ISO F...

What is the result of "nil%2" in objective-c ?

Hi, What is the answer to "nil%2" in objective-c? I think the answer is 0 but I am not sure. Thank you. ...

Sorting a list alphabetically with a modulus

I don't have any trouble grabbing a list of elements and sorting them alphabetically, but I'm having difficulty understanding how to do it with a modulus. ### UPDATE ### Here's the code working 'my way', however, I like the re-usability of the answer provided below more, so have accepted that answer. <script type="text/javascript"> $(...

Is there a way to optimize reducing many numbers to the same modulus

I am writing a program to do integer factorization and have to reduce a series of numbers to a given modulus. Both the number and the modulus are bigints, say 50 to 100 digits. The number changes but the modulus is always the same. Is there some way to optimize the repeated modulus calculations, perhaps by pre-computing some partial r...

Using mod operator in iOS app

I have an NSTimeInterval that is stored as a double. I would like to get the amount of minutes that are inide of the second value using the % operator. minutes = secondValue % 60; where minutes is declared as double minutes The result is that XCode says "Invalid operands to binary %" Thoughts? ...

if a five-digit number is input through the keyboard, write a program to calculate the sum of its digits?

how i add five digit number by using modulus. i am beginner. by using the example say 12345. reply me fast. ...

[SQL] select row if the "value" % 2 = 1. MOD()

There is a column in options that hold an integer. I want to select the row only if that value % 2 = 1. I know this can be done in 2 queries but is it possible to do it in 1? ...

Is there a standard Cyclic Integer Class in C++?

I have a problem that is quite common in the code that I am writing at the moment whereby I want to have an integer that can only exist inside a certain range where the range is [start, end). Basically I want to be able to do something like the following: cyclic_int ci(4, 8); ci = 4; assert(ci == 4); ci += 3; assert(ci == 7); ci += 2; ...

Using javascript modulus to iterate through text slider with for loop

Hi everyone, I'm new to jQuery and stack overflow, so I'll try to be specific, but please bear with me. I'm trying to create a text slider with associated links from scratch, using modulus to iterate through the list and repeat. Here's the code I'm working with: ul#text { position: relative; margin-bottom: 40px; height: 40px; } ul#tex...

Floating point numbers and JavaScript modulus operator

Why does 49.90 % 0.10 in JavaScript return 0.09999999999999581? I expected it to be 0. EDIT: Ok, I didn't know all this stuff about floating points. Thanks. My lecturers were slacking, it seems. ...