isNear.php
Table of Contents
Functions
- isNear() : bool
- Tells whether a ratio is within a relative tolerance of a target.
Functions
isNear()
Tells whether a ratio is within a relative tolerance of a target.
isNear(float $ratio, float $target, float $tolerance) : bool
Compares abs( $ratio - $target ) against abs( $target ) * $tolerance — the
allowed gap scales with the target's magnitude, so the same $tolerance reads
as a relative margin (e.g. 0.05 for "within 5%") rather than an absolute one,
regardless of the sign of $target.
Parameters
- $ratio : float
-
The value to test.
- $target : float
-
The reference value.
- $tolerance : float
-
The relative tolerance, as a fraction of
$target(e.g.0.05for 5%).
Tags
Return values
bool —true if $ratio lies within the tolerance band around $target, false otherwise.