Module: Compass::Core::SassExtensions::Functions::Math
- Extended by:
- SassDeclarationHelper, Sass::Script::Value::Helpers
- Defined in:
- lib/compass/core/sass_extensions/functions/math.rb
Constant Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #acos(number) ⇒ Object
- #asin(number) ⇒ Object
- #atan(number) ⇒ Object
- #cos(number) ⇒ Object
- #deprecated_random(*args) ⇒ Object
- #e ⇒ Object
- #logarithm(number, base = e) ⇒ Object
- #pi ⇒ Object
- #pow(number, exponent) ⇒ Object
- #sin(number) ⇒ Object
- #sqrt(number) ⇒ Object (also: #square_root)
- #tan(number) ⇒ Object
Methods included from SassDeclarationHelper
Class Method Details
Instance Method Details
#acos(number) ⇒ Object
50 51 52 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 50 def acos(number) trig(:acos, number) end |
#asin(number) ⇒ Object
40 41 42 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 40 def asin(number) trig(:asin, number) end |
#atan(number) ⇒ Object
60 61 62 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 60 def atan(number) trig(:atan, number) end |
#cos(number) ⇒ Object
45 46 47 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 45 def cos(number) trig(:cos, number) end |
#deprecated_random(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 20 def deprecated_random(*args) if args.length == 2 Compass::Util.compass_warn <<WARNING WARNING: The $start value for random(#{args.first}, #{args.last}) is not supported by Sass and is now deprecated in Compass and will be removed in a future release. Use `#{args.first} + random(#{args.last.minus(args.first)})` instead. WARNING range = (args.first.value..args.last.value).to_a number(range[rand(range.length)]) else sass_random(*args) end end |
#e ⇒ Object
65 66 67 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 65 def e E end |
#logarithm(number, base = e) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 70 def logarithm(number, base = e ) assert_type number, :Number assert_type base, :Number raise Sass::SyntaxError, "base to logarithm must be unitless." unless base.unitless? result = Math.log(number.value, base.value) rescue Math.log(number.value) / Math.log(base.value) number(result, number.unit_str) end |
#pi ⇒ Object
15 16 17 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 15 def pi() PI end |
#pow(number, exponent) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 89 def pow(number, exponent) assert_type number, :Number assert_type exponent, :Number raise Sass::SyntaxError, "exponent to pow must be unitless." unless exponent.unitless? number(number.value**exponent.value, number.unit_str) end |
#sin(number) ⇒ Object
35 36 37 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 35 def sin(number) trig(:sin, number) end |
#sqrt(number) ⇒ Object Also known as: square_root
81 82 83 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 81 def sqrt(number) numeric_transformation(number) { |n| Math.sqrt(n) } end |
#tan(number) ⇒ Object
55 56 57 |
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 55 def tan(number) trig(:tan, number) end |