module Compass::Core::SassExtensions::Functions::Math
Constants
- E
- PI
Public Class Methods
included(base)
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 5 def self.included(base) if base == Sass::Script::Functions base.send :alias_method, :sass_random, :random base.send :alias_method, :random, :deprecated_random end end
Public Instance Methods
acos(number)
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 50 def acos(number) trig(:acos, number) end
asin(number)
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 40 def asin(number) trig(:asin, number) end
atan(number)
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 60 def atan(number) trig(:atan, number) end
cos(number)
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 45 def cos(number) trig(:cos, number) end
deprecated_random(*args)
click to toggle source
# 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()
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 65 def e E end
logarithm(number, base = e )
click to toggle source
# 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()
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 15 def pi() PI end
pow(number, exponent)
click to toggle source
# 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)
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 35 def sin(number) trig(:sin, number) end
sqrt(number)
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 81 def sqrt(number) numeric_transformation(number) { |n| Math.sqrt(n) } end
Also aliased as: square_root
tan(number)
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 55 def tan(number) trig(:tan, number) end
Private Instance Methods
trig(operation, number)
click to toggle source
# File lib/compass/core/sass_extensions/functions/math.rb, line 98 def trig(operation, number) if number.unit_str == "deg" number(Math.send(operation, Math::PI * number.value / 180)) else number(Math.send(operation, number.value), number.unit_str) end end