// SASSY MATH
// https://github.com/Team-Sass/Sassy-math

// My light functions depend on these so I stole it
// Prefixed functions to avoid conflicts

$sg-pi: 3.1415926535897932384626433832795028841971693993751;
$sg-iter: 50;

@function _exponent($base, $exponent) {
  // reset value
  $value: $base;
  // positive intergers get multiplied
  @if $exponent > 1 {
    @for $i from 2 through $exponent {
      $value: $value * $base; } }
  // negitive intergers get divided. A number divided by itself is 1
  @if $exponent < 1 {
    @for $i from 0 through -$exponent {
      $value: $value / $base; } }
  // return the last value written
  @return $value;
}

@function _factorial($number) {
  // reset value
  $value: 1;
  // positive intergers get multiplied
  @if $number > 0 {
    @for $i from 1 through $number {
      $value: $value * $i;
    }
  }
  @return $value;
}

@function _maclaurin($start, $key, $number) {
  $value: $start;
  $add: 0;

  @for $i from 1 through $sg-iter {
    @if $add == 0 {
      $value: $value - ( _exponent($number, $key) / -factorial($key) );
      $add: 1;
    }
    @else {
      $value: $value + ( _exponent($number, $key) / -factorial($key) );
      $add: 0;
    }

    $key: $key + 2;
  }

  @return $value;
}

@function _deg-to-rad($number) {
  @return $number * $sg-pi / 180deg;
}

@function _rad-to-deg($number) {
  @return $number * 180deg / $sg-pi;
}

@function _sin($number, $unit: "deg") {
 @if $unit == "deg" {
   $number: _deg-to-rad($number);
 }
 @return _maclaurin($number, 3, $number);
}

@function _cos($number, $unit: "deg") {
 @if $unit == "deg" {
   $number: _deg-to-rad($number);
 }
 @return _maclaurin(1, 2, $number);
}
