Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

SCSSPHP

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

Defines 1 class

Number:: (38 methods):
  __construct()
  getDimension()
  getNumeratorUnits()
  getDenominatorUnits()
  offsetExists()
  offsetGet()
  offsetSet()
  offsetUnset()
  unitless()
  hasUnits()
  hasUnit()
  unitStr()
  valueInRange()
  valueInRangeWithUnit()
  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

hasUnits()   X-Ref
Returns true if the number has any units

return: bool

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

param: string $unit
return: bool

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

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

valueInRangeWithUnit($min, $max, $name, $unit)   X-Ref

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

assertNoUnits($varName = null)   X-Ref

param: string|null $varName
return: void

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

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

assertSameUnitOrUnitless(Number $other)   X-Ref

param: Number $other
return: void

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.

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

isComparableTo(Number $other)   X-Ref

param: Number $other
return: bool

lessThan(Number $other)   X-Ref

param: Number $other
return: bool

lessThanOrEqual(Number $other)   X-Ref

param: Number $other
return: bool

greaterThan(Number $other)   X-Ref

param: Number $other
return: bool

greaterThanOrEqual(Number $other)   X-Ref

param: Number $other
return: bool

plus(Number $other)   X-Ref

param: Number $other
return: Number

minus(Number $other)   X-Ref

param: Number $other
return: Number

unaryMinus()   X-Ref

return: Number

modulo(Number $other)   X-Ref

param: Number $other
return: Number

times(Number $other)   X-Ref

param: Number $other
return: Number

dividedBy(Number $other)   X-Ref

param: Number $other
return: Number

equals(Number $other)   X-Ref

param: Number $other
return: bool

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

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

__toString()   X-Ref
{@inheritdoc}


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

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

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

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

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

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

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

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

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

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

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

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

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