PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Division [maybe a bug]
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Division [maybe a bug]

Réponse
 
LinkBack Outils de la discussion
Vieux 10/05/2008, 23h16   #1
jo opp
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Division [maybe a bug]

Hello!

$var1= 2155243640%31104000;
$var2= 2147309244%31104000;

echo $var1 // Return -24651656
echo $var2 // Return 1133244

$var2 return the correct result, but $var1 is wrong (the correct
result is 9067640)

¿?

Thanks for the
  Réponse avec citation
Vieux 11/05/2008, 05h33   #2
Chris W
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Division [maybe a bug]

jo opp wrote:
> Hello!
>
> $var1= 2155243640%31104000;
> $var2= 2147309244%31104000;
>
> echo $var1 // Return -24651656
> echo $var2 // Return 1133244
>
> $var2 return the correct result, but $var1 is wrong (the correct
> result is 9067640)


Probably because the maximum signed 32 bit integer value is
2,147,483,648

if you are dealing with numbers that large, consider using some
arbitrary precision math functions that can work with as large of
numbers as you need.


http://us3.php.net/manual/en/refs.mathcrypto.math.php



--
Chris W
KE5GIX

"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm"

Ham Radio Repeater Database.
http://hrrdb.com
  Réponse avec citation
Vieux 11/05/2008, 16h08   #3
jo opp
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Division [maybe a bug]

2008/5/11 Chris W <2wsxdr5@cox.net>:
> jo opp wrote:
>
> > Hello!
> >
> > $var1= 2155243640%31104000;
> > $var2= 2147309244%31104000;
> >
> > echo $var1 // Return -24651656
> > echo $var2 // Return 1133244
> >
> > $var2 return the correct result, but $var1 is wrong (the correct
> > result is 9067640)
> >

>
> Probably because the maximum signed 32 bit integer value is
> 2,147,483,648
>


OK, but with bigger numbers works fine again.
Right now I made a function to deal with this issue:

function remainder($dividend,$divisor){
$remainder= $dividend-(floor($dividend/$divisor)*$divisor);
return $remainder;
}

What do you think about it?

> if you are dealing with numbers that large, consider using some arbitrary
> precision math functions that can work with as large of numbers as you need.
>
>
> http://us3.php.net/manual/en/refs.mathcrypto.math.php
>
>
>
> --
> Chris W
> KE5GIX
>
> "Protect your digital freedom and privacy, eliminate DRM,
> learn more at http://www.defectivebydesign.org/what_is_drm"
>
> Ham Radio Repeater Database.
> http://hrrdb.com
>

  Réponse avec citation
Vieux 12/05/2008, 02h59   #4
Chris W
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Division [maybe a bug]

jo opp wrote:
> 2008/5/11 Chris W <2wsxdr5@cox.net>:
>> jo opp wrote:
>>
>>> Hello!
>>>
>>> $var1= 2155243640%31104000;
>>> $var2= 2147309244%31104000;
>>>
>>> echo $var1 // Return -24651656
>>> echo $var2 // Return 1133244
>>>
>>> $var2 return the correct result, but $var1 is wrong (the correct
>>> result is 9067640)
>>>

>> Probably because the maximum signed 32 bit integer value is
>> 2,147,483,648
>>

>
> OK, but with bigger numbers works fine again.
> Right now I made a function to deal with this issue:
>
> function remainder($dividend,$divisor){
> $remainder= $dividend-(floor($dividend/$divisor)*$divisor);
> return $remainder;
> }
>
> What do you think about it?
>


That will convert the numbers to floating point, which will give you
round off error if the numbers get too big.

--
Chris W
KE5GIX

"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm"

Ham Radio Repeater Database.
http://hrrdb.com
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 06h49.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08902 seconds with 12 queries