Math stuff done

Though I really ought to make the sign determination it's own function.