/** * Creates a sequence of evenly spaced values starting at {@code min} and * ending at {@code max}. If {@code (max - min) / step} is not integer * valued, the last step in the sequence will be {@code <step}. * @param min sequence value * @param max sequence value * @param step sequence spacing * @param ascending if {@code true}, descending if {@code false} * @return a monotonically increasing or decreasing sequence of values */ public static function buildSequence($min, $max, $step, $ascending) { // if passed in arguments are NaN, +Inf, or -Inf, and step <= 0, // then capacity [c] will end up 0 because (int) NaN = 0, or outside the // range 1:10000 $c = intval(($max - $min) / $step); if ($c <= 0) { return; } else { if ($c >= RTGM_Util::MAX_SEQ_LEN) { throw new Exception("RTGM_Util::buildSequence: max sequence " . "length reached: " . RTGM_Util::MAX_SEQ_LEN); } } if ($ascending) { return RTGM_Util::makeSequence($min, $max, $step, $c + 2); } $descSeq = RTGM_Util::makeSequence(-$max, -$min, $step, $c + 2); return RTGM_Util::flip($descSeq); }