nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lib/standard: `Text::to_n` returns 0 as failsafe when receiver is empty
[nit.git]
/
lib
/
standard
/
numeric.nit
diff --git
a/lib/standard/numeric.nit
b/lib/standard/numeric.nit
index
1d2e30c
..
92fe49a
100644
(file)
--- a/
lib/standard/numeric.nit
+++ b/
lib/standard/numeric.nit
@@
-30,9
+30,11
@@
redef class Text
# assert "0.0".to_n == 0.0
# assert ".12345".to_n == 0.12345
# assert "12345".to_n == 12345
# assert "0.0".to_n == 0.0
# assert ".12345".to_n == 0.12345
# assert "12345".to_n == 12345
+ # assert "".to_n == 0
# ~~~~
fun to_n: Numeric
do
# ~~~~
fun to_n: Numeric
do
+ if is_empty then return 0
if chars.has('.') then return to_f
return to_i
end
if chars.has('.') then return to_f
return to_i
end