HumHub Documentation (unofficial)

HTMLPurifier_UnitConverter
in package

Class for converting between different unit-lengths as specified by CSS.

Table of Contents

Constants

DIGITAL  = 3
ENGLISH  = 1
METRIC  = 2

Properties

$internalPrecision  : mixed
Bcmath precision for internal calculations.
$outputPrecision  : mixed
Minimum bcmath precision for output.
$units  : mixed
Units information array. Units are grouped into measuring systems (English, Metric), and are assigned an integer representing the conversion factor between that unit and the smallest unit in the system. Numeric indexes are actually magical constants that encode conversion data from one system to the next, with a O(n^2) constraint on memory (this is generally not a problem, since the number of measuring systems is small.)
$bcmath  : mixed
Whether or not BCMath is available.

Methods

__construct()  : mixed
convert()  : HTMLPurifier_Length|bool
Converts a length object of one unit into another unit.
getSigFigs()  : int
Returns the number of significant figures in a string number.
add()  : string
Adds two numbers, using arbitrary precision when available.
div()  : string
Divides two numbers, using arbitrary precision when available.
mul()  : string
Multiples two numbers, using arbitrary precision when available.
round()  : string
Rounds a number according to the number of sigfigs it should have, using arbitrary precision when available.
scale()  : string
Scales a float to $scale digits right of decimal point, like BCMath.

Constants

Properties

$internalPrecision

Bcmath precision for internal calculations.

protected mixed $internalPrecision
Tags
type

int

$outputPrecision

Minimum bcmath precision for output.

protected mixed $outputPrecision
Tags
type

int

$units

Units information array. Units are grouped into measuring systems (English, Metric), and are assigned an integer representing the conversion factor between that unit and the smallest unit in the system. Numeric indexes are actually magical constants that encode conversion data from one system to the next, with a O(n^2) constraint on memory (this is generally not a problem, since the number of measuring systems is small.)

protected static mixed $units = array(self::ENGLISH => array( 'px' => 3, // This is as per CSS 2.1 and Firefox. Your mileage may vary 'pt' => 4, 'pc' => 48, 'in' => 288, self::METRIC => array('pt', '0.352777778', 'mm'), ), self::METRIC => array('mm' => 1, 'cm' => 10, self::ENGLISH => array('mm', '2.83464567', 'pt')))

$bcmath

Whether or not BCMath is available.

private mixed $bcmath
Tags
type

bool

Methods

__construct()

public __construct([mixed $output_precision = 4 ][, mixed $internal_precision = 10 ][, mixed $force_no_bcmath = false ]) : mixed
Parameters
$output_precision : mixed = 4
$internal_precision : mixed = 10
$force_no_bcmath : mixed = false

convert()

Converts a length object of one unit into another unit.

public convert(HTMLPurifier_Length $length, string $to_unit) : HTMLPurifier_Length|bool
Parameters
$length : HTMLPurifier_Length

Instance of HTMLPurifier_Length to convert. You must validate() it before passing it here!

$to_unit : string

Unit to convert to.

Tags
note

About precision: This conversion function pays very special attention to the incoming precision of values and attempts to maintain a number of significant figure. Results are fairly accurate up to nine digits. Some caveats: - If a number is zero-padded as a result of this significant figure tracking, the zeroes will be eliminated. - If a number contains less than four sigfigs ($outputPrecision) and this causes some decimals to be excluded, those decimals will be added on.

Return values
HTMLPurifier_Length|bool

getSigFigs()

Returns the number of significant figures in a string number.

public getSigFigs(string $n) : int
Parameters
$n : string

Decimal number

Return values
int

number of sigfigs

add()

Adds two numbers, using arbitrary precision when available.

private add(string $s1, string $s2, int $scale) : string
Parameters
$s1 : string
$s2 : string
$scale : int
Return values
string

div()

Divides two numbers, using arbitrary precision when available.

private div(string $s1, string $s2, int $scale) : string
Parameters
$s1 : string
$s2 : string
$scale : int
Return values
string

mul()

Multiples two numbers, using arbitrary precision when available.

private mul(string $s1, string $s2, int $scale) : string
Parameters
$s1 : string
$s2 : string
$scale : int
Return values
string

round()

Rounds a number according to the number of sigfigs it should have, using arbitrary precision when available.

private round(float $n, int $sigfigs) : string
Parameters
$n : float
$sigfigs : int
Return values
string

scale()

Scales a float to $scale digits right of decimal point, like BCMath.

private scale(float $r, int $scale) : string
Parameters
$r : float
$scale : int
Return values
string

        
On this page

Search results