Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

SCSSPHP

Copyright: 2012-2020 Leaf Corcoran
License: http://opensource.org/licenses/MIT MIT
File Size: 804 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Number:: (36 methods):
  __construct()
  getDimension()
  getNumeratorUnits()
  getDenominatorUnits()
  offsetExists()
  offsetGet()
  offsetSet()
  offsetUnset()
  unitless()
  hasUnit()
  unitStr()
  valueInRange()
  assertNoUnits()
  assertUnit()
  assertSameUnitOrUnitless()
  coerce()
  isComparableTo()
  lessThan()
  lessThanOrEqual()
  greaterThan()
  greaterThanOrEqual()
  plus()
  minus()
  unaryMinus()
  modulo()
  times()
  dividedBy()
  equals()
  output()
  __toString()
  coerceNumber()
  coerceUnits()
  valueInUnits()
  multiplyUnits()
  getConversionFactor()
  getUnitString()


Class: Number  - X-Ref

Dimension + optional units

{@internal
This is a work-in-progress.

The \ArrayAccess interface is temporary until the migration is complete.
}}

__construct($dimension, $numeratorUnits, array $denominatorUnits = [])   X-Ref
Initialize number

param: int|float       $dimension
param: string[]|string $numeratorUnits
param: string[]        $denominatorUnits

getDimension()   X-Ref

return: float|int

getNumeratorUnits()   X-Ref

return: string[]

getDenominatorUnits()   X-Ref

return: string[]

offsetExists($offset)   X-Ref

return: bool

offsetGet($offset)   X-Ref

return: mixed

offsetSet($offset, $value)   X-Ref

return: void

offsetUnset($offset)   X-Ref

return: void

unitless()   X-Ref
Returns true if the number is unitless

return: bool

hasUnit($unit)   X-Ref
Checks whether the number has exactly this unit

return: bool
param: string $unit

unitStr()   X-Ref
Returns unit(s) as the product of numerator units divided by the product of denominator units

return: string

valueInRange($min, $max, $name = null)   X-Ref

return: float|int
param: float|int $min
param: float|int $max
param: string|null $name

assertNoUnits($varName = null)   X-Ref

return: void
param: string|null $varName

assertUnit($unit, $varName = null)   X-Ref

return: void
param: string      $unit
param: string|null $varName

assertSameUnitOrUnitless(Number $other)   X-Ref

return: void
param: Number $other

coerce(array $newNumeratorUnits, array $newDenominatorUnits)   X-Ref
Returns a copy of this number, converted to the units represented by $newNumeratorUnits and $newDenominatorUnits.

This does not throw an error if this number is unitless and
$newNumeratorUnits/$newDenominatorUnits are not empty, or vice versa. Instead,
it treats all unitless numbers as convertible to and from all units without
changing the value.

return: Number
param: string[] $newNumeratorUnits
param: string[] $newDenominatorUnits

isComparableTo(Number $other)   X-Ref

return: bool
param: Number $other

lessThan(Number $other)   X-Ref

return: bool
param: Number $other

lessThanOrEqual(Number $other)   X-Ref

return: bool
param: Number $other

greaterThan(Number $other)   X-Ref

return: bool
param: Number $other

greaterThanOrEqual(Number $other)   X-Ref

return: bool
param: Number $other

plus(Number $other)   X-Ref

return: Number
param: Number $other

minus(Number $other)   X-Ref

return: Number
param: Number $other

unaryMinus()   X-Ref

return: Number

modulo(Number $other)   X-Ref

return: Number
param: Number $other

times(Number $other)   X-Ref

return: Number
param: Number $other

dividedBy(Number $other)   X-Ref

return: Number
param: Number $other

equals(Number $other)   X-Ref

return: bool
param: Number $other

output(Compiler $compiler = null)   X-Ref
Output number

return: string
param: \ScssPhp\ScssPhp\Compiler $compiler

__toString()   X-Ref
{@inheritdoc}


coerceNumber(Number $other, $operation)   X-Ref

return: Number
param: Number   $other
param: callable $operation

coerceUnits(Number $other, $operation)   X-Ref

return: mixed
param: Number $other
param: callable $operation

valueInUnits(array $numeratorUnits, array $denominatorUnits)   X-Ref

return: int|float
param: string[] $numeratorUnits
param: string[] $denominatorUnits

multiplyUnits($value, array $numerators1, array $denominators1, array $numerators2, array $denominators2)   X-Ref

return: Number
param: int|float $value
param: string[] $numerators1
param: string[] $denominators1
param: string[] $numerators2
param: string[] $denominators2

getConversionFactor($unit1, $unit2)   X-Ref
Returns the number of [unit1]s per [unit2].

Equivalently, `1unit1 * conversionFactor(unit1, unit2) = 1unit2`.

return: float|int|null
param: string $unit1
param: string $unit2

getUnitString(array $numerators, array $denominators)   X-Ref
Returns unit(s) as the product of numerator units divided by the product of denominator units

return: string
param: string[] $numerators
param: string[] $denominators