blob: 9b71bf627229a46a6b9dccf09e0ff4779bb15e55 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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;
}
|