math: digits panic for invalid base

pull/2728/head
Daren Liang 2019-11-10 21:21:47 -05:00 committed by Alexander Medvednikov
parent 887c94d9ba
commit 91896af877
1 changed files with 3 additions and 0 deletions

View File

@ -99,6 +99,9 @@ pub fn exp(a f64) f64 {
// digits returns an array of the digits of n in the given base.
pub fn digits(_n, base int) []int {
if base < 2 {
panic('digits: Cannot find digits of n with base $base')
}
mut n := _n
mut sign := 1
if n < 0 {