PDA

View Full Version : Big Numbers


arne2
09-08-2006, 04:26 PM
Hi,
i have a gaming website and encountered a problem.
When players get a very large number of a certain item (let's say : toys), then i get problems.

I don't know if the problems are related to the SQL limit or the php query limit or ...
Could anybody explain the problem / Tell me how to fix it?

THE NUMBERS THAT SEEM TO BE THE LIMIT :
2147483647 (it can't get any higher than that, the sql type is 'bigint(100)';
(it does simple things with this number (+ - ,...))
I would like to make the limit higher of that number.
Also :
When somebody bought more than 1 000 000 000 000 (1 Trillion) it is being stored in the database and then when they do something that uses that number, they get back to 1 (total mystery to me)!

Could anybody tell me more about limits and how to raise them if possible?! Or how to solve the problem in a different way? Should i use the type 'unsigned' ? Will that make the limit of the numbers bigger? Or long?

Lee Stevens
09-08-2006, 05:19 PM
Store it as Text, instead of Bigint......

guelphdad
09-08-2006, 05:36 PM
If the largest value you are using is:
2147483647
then you are using INT and not BIGINT.
An unsigned BIGINT column type can hold a value of
18446744073709551615

which is significantly larger than 1 trillion.

The problem you have is that you assume that the (100) after your column type tells you how many digits fit into the column. that is incorrect. the column type determines that as I've shown above. the number after the column type tells how many digits to pad the field out to when using zerofill.

if you use BIGINT(5) and store a value of 3 in the column when you use zerofill on the column the value is displayed as 00003 in other words five digits minimum, with zeros padding the column display out.

the reason you are getting 1 back is you have stored a value too large for your INT type column. change it to UNSIGNED BIGINT, drop the (100) after it and you will be fine.

arne2
09-08-2006, 06:41 PM
i changed it to bigint (5) extra: unsigned
but still it isn't totally working. When someone does something with then number, sometimes it works, but not always
It outputs stuff like 9 / 5 / 1 instead of 1,000,000,000,987 for example. Maybe PHP can't handle using the numbers to do simple math actions like + and - ?

marek_mar
09-08-2006, 08:12 PM
PHP can't do math on such numbers unless you are using either GMP (http://www.php.net/gmp), BCMath (http://www.php.net/bc) or BigInt. If you are doing mathematical operations on such numbers the result won't be correct before you try to insert it to the database.

arne2
09-09-2006, 10:03 AM
When you have the BCmath activated, what should you do in order to make it work with the function, so it calculates correctly? I went to php.net but i don't understand it..

arne2
09-09-2006, 10:24 AM
it are not comma numbers (so not : 1,24). Only very big numbers (without decimals). How to do + , - , * AND / ?

My hosting said BCmath was enabled.
Also, i've read some about BCmath and something about making sure the scale is right or something? Could anyone make an example + - * ANd / operation?

THANK YOU

arne2
09-09-2006, 10:51 AM
Hi, i tried to change something into BCmath , this is what i got but it's not workiong:

$usecondom=round(($user["condom"]-($user["hoes"]*0.08)*$turns));

should be changed into BCmath, this is what i've got:

//$hoesuse = bcmul((float)$user["hoes"], (float)0.08);
//$condomsusedoneturn=bcsub((float)$user["condom"], (float)$hoesuse);
//$multiplybyturns=bcmul((float)$condomsusedoneturn, (float)$turns);
//$usecondom=$multiplybyturns;
But it's not correct. I probably did something wrong could anybody tell me what?

marek_mar
09-09-2006, 11:06 AM
<?php
bcscale(15);
$number = bcmul(bcsub($user["condom"], bcmul($user["hoes"], '0.08')), $turns);
?>

arne2
09-09-2006, 11:36 AM
<?php
bcscale(15);
$number = bcmul(bcsub($user["condom"], bcmul($user["hoes"], '0.08')), $turns);
?>


changed bcscale to 1 because i don't need commanumbers.

About the $number calculation.
If i interpretate it right, you do this : (($usercondom - $userhoes)*0.08)
but you should do ($usercondoms-($userhoes*0.08))?
RIGHT? (because i don't fully understand the functions yet)

How bout adding a value in it too:
$useweed=round(($user["weed"]-(($user["thugs"]*0.10)+($user["dealers"]*0.05))*$turns));

arne2
09-09-2006, 05:05 PM
ok, I fully understand how to use the BC functions now. But is it possible that even that gets too big numbers after a while?

marek_mar
09-09-2006, 07:44 PM
changed bcscale to 1 because i don't need commanumbers.

You should use a high sacale as the bc functions round after every operation and your final result will be wrong.

About the $number calculation.
If i interpretate it right, you do this : (($usercondom - $userhoes)*0.08)

No I don't.
ok, I fully understand how to use the BC functions now. But is it possible that even that gets too big numbers after a while?
No it won't.

guelphdad
09-09-2006, 09:24 PM
well if you are storing in the database, yes your number could conceivable get too big. your initial post though said you were working in the range of a possible trillion items. BIGINT will hold a value in the order of magnitude 10 million times greater than that.