Asked  2 Years ago    Answers:  5   Viewed   54 times

Derived from this question : (Java) How does java do modulus calculations with negative numbers?

Anywhere to force PHP to return positive 51?

update
Looking for a configuration setting to fix, instead hard-guessing

Or other math function like bcmath?

updated
Not entire convinced by that java answer, as it does not take account of negative modulus -13+(-64) =?

 Answers

5

If GMP is available, you can use gmp_mod

Calculates n modulo d. The result is always non-negative, the sign of d is ignored.

Example:

echo gmp_strval(gmp_mod('-13', '64')); // 51

Note that n and d have to be GMP number resources or numeric strings. Anything else won't work¹

echo gmp_strval(gmp_mod(-13, 64));
echo gmp_mod(-13, 64);

will both return -51 instead (which is a bug).

¹ running the above in this codepad, will produce 51 in all three cases. It won't do that on my development machine.

Monday, September 19, 2022
 
4

As others have noted, most likely you don't have .html set up to handle php code.

Having said that, if all you're doing is using index.html to include index.php, your question should probably be 'how do I use index.php as index document?

In which case, for Apache (httpd.conf), search for DirectoryIndex and replace the line with this (will only work if you have dir_module enabled, but that's default on most installs):

DirectoryIndex index.php

If you use other directory indexes, list them in order of preference i.e.

DirectoryIndex index.php index.phtml index.html index.htm
Wednesday, December 14, 2022
1

Modulus returns the remainder, not a boolean value.

This code will resolve to true for 1, 3, 6, 9, ...

if (($k % 3 == 0) || $k==1 ) { echo '<div class="modcontainer">'; } 

This code will resolve to true for 1, 4, 7, 10, ...

if ($k % 3 == 1) { echo '<div class="modcontainer">'; } 
Saturday, November 26, 2022
1

It's giving you the reminder of the division what you need is fmod,

fmodReturns the floating point remainder (modulo) of the division of the arguments

echo fmod(877.5, 1); // 0.5
Tuesday, August 9, 2022
 
treeki
 
5

Turns out because I was using php-fpm, there were settings I wasn't aware were set living in /etc/php5/mods-available/zzzz_custom.ini.

Adding the sendmail path to that file worked for me :

sendmail_path=/usr/sbin/sendmail -t -i
Monday, August 22, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages