From d07f664450ddaaebb44127a4bd057763d13d3f82 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Sun, 1 Nov 2020 20:55:14 +0100 Subject: Init --- src/_math.scss | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/_math.scss (limited to 'src/_math.scss') diff --git a/src/_math.scss b/src/_math.scss new file mode 100644 index 0000000..9b71bf6 --- /dev/null +++ b/src/_math.scss @@ -0,0 +1,62 @@ +//// +/// Basic mathematical functions. +/// +/// @group Math functions +/// +/// @access public +//// + +/// +/// Perform exponentiation. Only integer exponents are supported. +/// +/// @param {number} $base +/// @param {number} $exp +/// +/// @return {number} +/// +/// @example scss - Exponentiation with a positive exponent +/// $result: iro-math-pow(3, 2); // The value of $result is 3^2 = 9 +/// +/// @example scss - Exponentiation with a negative exponent +/// $result: iro-math-pow(2, -3); // The value of $result is 1/(2^3) = 1/8 +/// +@function iro-math-pow($base, $exp) { + $value: 1; + + @if $exp > 0 { + @for $i from 1 through $exp { + $value: $value * $base; + } + } @else if $exp < 0 { + @for $i from 1 through -$exp { + $value: $value / $base; + } + } + + @return $value; +} + +/// +/// Clamp a number between a minimum and maximum value. +/// +/// @param {number} $value - Value to clamp +/// @param {number} $min - Minimum value +/// @param {number} $max - Maximum value +/// +/// @return {number} +/// +/// @example scss +/// $result: iro-math-clamp(20, 0, 10); // The value of $result is 10 +/// +/// @example scss +/// $result: iro-math-clamp(50, 20, 100); // The value of $result is 50 +/// +@function iro-math-clamp($value, $min, $max) { + @if $value < $min { + @return $min; + } + @if $value > $max { + @return $max; + } + @return $value; +} -- cgit v1.2.3-54-g00ecf