![]() |
![]() |
#1 |
Feb 2014
22×3×7 Posts |
![]()
I've posted a call for help on stackoverflow as well as Googled the dickens out of the error message I'm receiving but nothing is coming up. So, I thought I'd post my plea for help here and maybe some math guru here can help me solve this issue.
Anyway, I've written (probably poorly written) a PHP program that tests a number for primality and if it is prime adds it to a database. However, about every 6 hours or so the program crashes. I have other programs using PHP GMP and long loops that have run for days without crashing so I don't see what is wrong with this particular program. Maybe one of you can see the issue. Here is the error I keep getting: PHP Warning: gmp_mod(): -2147483648 is not a valid GMP integer resource in /SSD/PrimeBasket/PrimeNumberBasket.php on line 100Attached is a copy of the program itself. Thanks in advance for any help someone may offer! :-) |
![]() |
![]() |
![]() |
#2 | |
"Ed Hall"
Dec 2009
Adirondack Mtns
10101001010002 Posts |
![]() Quote:
Maybe a 32-bit issue? |
|
![]() |
![]() |
![]() |
#3 |
Jun 2005
USA, IL
193 Posts |
![]()
See the following page under section "Example #3 Integer overflow on a 32-bit system".
http://us3.php.net/manual/en/language.types.integer.php That number is treated as a float, not an integer. |
![]() |
![]() |
![]() |
#4 | ||
Feb 2014
10101002 Posts |
![]() Quote:
The odd thing is that the only time I modify the $NumberToTest variable is at the end of the loop when I add 2 to it (to get the next odd number) and I haven't even come close to exceeding 2^32 sized number (I'm only in the 550*10^6 range). So, what do you think this could be??? EDIT: I added a print of $NumberToTest to print out not as a string but as a raw Resource variable every 12345 loops and I find something interesting! Quote:
Last fiddled with by daxmick on 2014-02-14 at 00:04 |
||
![]() |
![]() |
![]() |
#5 |
If I May
"Chris Halsall"
Sep 2002
Barbados
2BB616 Posts |
![]() |
![]() |
![]() |
![]() |
#6 |
Feb 2014
22·3·7 Posts |
![]() |
![]() |
![]() |
![]() |
#7 | |
If I May
"Chris Halsall"
Sep 2002
Barbados
2×3×5×373 Posts |
![]() Quote:
Please give specific examples (exact code, exact input and exact output), and we'll take you seriously. Otherwise you're just a waste of carbon (sorry if that comes across as mean, but some of us actually have real jobs). |
|
![]() |
![]() |
![]() |
#8 | |
Feb 2014
22×3×7 Posts |
![]() Quote:
I thought I did give output from my code... or at least the error that I'm seeing. If you'd read my code you'd see that technically there is no output. The "output" is just a list of prime numbers and those are put in a sqlite db. Just in case you didn't see the first post's attachment here it is again. Your comments are not only mean but rude. So far you've only just negatively commented without any reason or purpose. Directly attacking someone (especially first off with no obvious reason) isn't a basis for a good interaction. Suggesting someone is a "waste of carbon" leaves little in the way of being socialable. Are you trying to get people to not post questions here by scaring them away or do you just have no social interaction skills. |
|
![]() |
![]() |
![]() |
#9 |
Jun 2005
USA, IL
3018 Posts |
![]()
I hope I am explaining this correctly, but the 32-bit limit is for the number of digits of the integer in base 2. If your process is 32-bit, you can't exceed that limit no matter what base your numbers are in (while dealing with the numbers as just integers).
It's been too long since I've had to troubleshoot PHP. Rather than work out your current code issue, based on what you want, have you considered just calling gmp_nextprime over and over starting at 2, and using the last result in each loop? Last fiddled with by potonono on 2014-02-14 at 02:42 |
![]() |
![]() |
![]() |
#10 | |
Mar 2006
541 Posts |
![]() Quote:
http://www.php.net/manual/en/sqlite3...fetcharray.php Maybe your query is returning empty rows. To that point, maybe there are empty rows in your db? Try to look in your db to see if this may be the case. Or, maybe you should use fetchArray(SQLITE3_ASSOC) to guarantee you can call into the resultant array by string name 'thenumber'. Also, can your gmp_cmp use the integer 0 as a value? Or should you be comparing against the string '0'? And, maybe the same thing for your gmp_add. Can you use the integer 1 as a value, or should that be the string value '1'? I haven't programmed too much in PHP, but hopefully this will give you some things to look into to see if you can narrow down where the problem is coming from. |
|
![]() |
![]() |
![]() |
#11 | ||
Feb 2014
22×3×7 Posts |
![]() Quote:
Quote:
Thanks for the thought though! |
||
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Rho code | Happy5214 | YAFU | 3 | 2015-11-01 21:54 |
Code Help | Andrew | Programming | 12 | 2013-02-16 20:53 |
New Code | JohnFullspeed | Programming | 20 | 2011-09-04 04:28 |
Code | Primeinator | Software | 20 | 2009-06-11 22:22 |
A little help with VBS code | IronBits | No Prime Left Behind | 6 | 2008-11-12 14:23 |