mathx

Small integer math helpers (clampi, sqi).

v1.0.0Math, time & IDscommunity registryhphp install mathx
Overview Installation Documentation Examples

Overview

Tiny integer math helpers for HolyPHP: clamp integers into a range and compute squares. Also used as the example package in the Packages walkthrough.

community registry zero dependencies clampi & sqi

Quick start

import "mathx";

echo "clamped: " . clampi(42, 0, 10);  // 10
echo "squared: " . sqi(7);             // 49

Installation

In a project

Inside a project (a folder with hphp.yaml, see Projects & packages):

hphp install mathx

This downloads mathx from the community registry (http://hphp.ch:8930), shows a permission summary for review, adds it to hphp.yaml, installs it into .hphp/packages/mathx/ and pins its checksum in hphp.lock:

require:
  mathx: "^1.0"

Outside a project

hphp pkg install mathx      # install globally into $HPHP_HOME/packages
hphp create myapp                 # or start a project, then: hphp install mathx

Use it

import "mathx";

In non-interactive environments (CI), pass --trust to accept a community package without prompting (hphp install --trust). See Official and community packages.

Packagemathx
Version1.0.0
SourceCommunity registry (http://hphp.ch:8930)
Entry filemathx.hphp

Documentation

API Reference

Examples

01Clamping and squaring integers

Install mathx from the community registry, then import it in any HolyPHP file.

import "mathx";

println("clamped high: " . clampi(42, 0, 10));   // 10
println("clamped low:  " . clampi(-5, 0, 10));   // 0
println("squared:      " . sqi(9));              // 81
Try it
hphp install mathx
hphp run main.hphp