Module: Compass::Core::SassExtensions::Functions::Math

Extended by:
SassDeclarationHelper, Sass::Script::Value::Helpers
Included in:
GradientSupport::CSS3AngleToSVGConverter, Sass::Script::Functions
Defined in:
lib/compass/core/sass_extensions/functions/math.rb

Constant Summary collapse

PI =
number(Math::PI)
E =
number(Math::E)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SassDeclarationHelper

declare

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
# 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

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

#eObject



65
66
67
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 65

def e
  E
end

#logarithm(number, base = e) ⇒ Object

Raises:

  • (Sass::SyntaxError)


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

#piObject



15
16
17
# File 'lib/compass/core/sass_extensions/functions/math.rb', line 15

def pi()
  PI
end

#pow(number, exponent) ⇒ Object

Raises:

  • (Sass::SyntaxError)


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