is there any value which can break the following code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

is there any value which can break the following code

Post by dude81 »

Hi,

I've the following case where $number1 and number2 which can also be a float value in which case values after decimal can go upto 10 to 15 digits. Can PHP5 handle such a float value. If so, does any value which doesnot fall in any of the following range can break the logic written below. -30 to + 30 for number1 and -100 to +100 for number2 .

Code: Select all

if(($number1 >= -30 && $number2 >= -100)&&($number1 <= 30 && $number2 <= 100)){
echo "Nothing broke the value";
  
}
I've tested most cases. But still I've some apprhensions about the logic
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Shift the logic around to group $number1 and $number2 together. Since everything is logical ands, you can lose the grouping parentheses too.

If you need to keep the precision high, use bcmath.
Post Reply