@function ballistic-convert($number, $unit, $ref: null) {
  $fail: "Can't convert #{$number} to #{$unit}. ";

  $convert: null;

  $unit-1: unit($number);
  $unit-2: $unit;

  $list-1: null;
  $list-2: null;

  $ref-1: null;
  $ref-2: null;

  $lists: (
    (1px,  1),
    (1pc,  0.0625),
    (1pt,  0.75),
    (1in,  0.0104166666666666666666666666666),
    (1cm,  0.0264583333333333333333333333333),
    (1mm,  0.2645833333333333333333333333333),
    (1em,  null),
    (1rem, null),
    (1ex,  null),
    (1ch,  null),
    (100%, null)
  ), (
    (1ms, 1),
    (1s,  0.001)
  ), (
    (1deg,  1),
    (1grad, 1.111111111111111111111111111111),
    (1rad,  0.01745329252),
    (1turn, 0.002777777777777777777777777777)
  );

  @each $list in $lists {
    @each $item in $list {
      @if unit(nth($item, 1)) == $unit-1 { $list-1: $list; $ref-1: nth($item, 2); }
      @if unit(nth($item, 1)) == $unit-2 { $list-2: $list; $ref-2: nth($item, 2); $convert: nth($item, 1) }
    }
  }

  @if $list-1 != $list-2 {
    @return ballistic-warn($fail + "Incompatible unit types.");
  }

  $number: ballistic-parse-int($number);

  $mod: null;

  @if $ref != null { $ref: 1 / $ref }

  @if $ref-1 == null and $ref-2 == null and $ref != null { $mod: $ref            }
  @if $ref-1 != null and $ref-2 == null and $ref != null { $mod: $ref   / $ref-1 }
  @if $ref-1 == null and $ref-2 != null and $ref != null { $mod: $ref-2 / $ref   }
  @if $ref-1 != null and $ref-2 != null                  { $mod: $ref-2 / $ref-1 }

  @if $mod != null {
    @return $number * $mod * $convert;
  } @else {
    @return ballistic-warn($fail + "Needs Reference.");
  }
}
