Jump to content

if and relative equality


blueman378

Recommended Posts

hi guys,

 

well as we all know floating point math is not exact,

 

so i need to create an if statement to check equality of a number within a given error range

 

eg we are looking for the equality of .99 with an error margin of .0001

 

so i need to find out if the difference between a and b is less than .0001

 

what do i need for this?

Link to comment
https://forums.phpfreaks.com/topic/170592-if-and-relative-equality/
Share on other sites

hi guys,

 

well as we all know floating point math is not exact,

 

so i need to create an if statement to check equality of a number within a given error range

 

eg we are looking for the equality of .99 with an error margin of .0001

 

so i need to find out if the difference between a and b is less than .0001

 

what do i need for this?

 

Like you already pointed out floating points in PHP are not exact and the manual tells you to use the arbitrary precision math functions as they do what their name says. http://www.php.net/manual/en/ref.bc.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.