June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,10 @@
~:0\`#v_:"+"-!#v_:"-"-!#v_::"E"-\"e"-*#v_ v
v _v# < < 0<
>~:0\`#v_>::"0"-0\`\"9"-0`+!#v_:"."-!#v_::"E"-\"e"-*!#v_ v
^ $< > > $ v
>~:0\`#v_>::"0"-0\`\"9"-0`+!#v_:"."-!#v_::"E"-\"e"-*!#v_> v>
^ $< >$~:0\`#v_:"+"-#v_v
v $_v# < < :#<
>~:0\`#v_>::"0"-0\`\"9"-0`+!#v_:"."-!#v_::"E"-\"e"-*!v 0 > v
^ $< v < << ^_^#-"-"<
> "ciremuN">:#,_@ >>#$_"ciremun toN">:#,_@^ <

View file

@ -1,23 +1,9 @@
function isnumeric{T<:String}(s::T)
isa(parse(s), Number)
end
isnumeric(s::AbstractString) = parse(s) isa Number
tests = ["1",
"-121",
"one",
"pi",
"1 + 1",
"NaN",
"1234567890123456789",
"1234567890123456789123456789",
"1234567890123456789123456789.0",
"1.3",
"1.4e10",
"Inf",
"1//2",
"1.0 + 1.0im"]
tests = ["1", "-121", "one", "pi", "1 + 1", "NaN", "1234567890123456789", "1234567890123456789123456789",
"1234567890123456789123456789.0", "1.3", "1.4e10", "Inf", "1//2", "1.0 + 1.0im"]
for t in tests
fl = isnumeric(t) ? "is" : "is not"
println(@sprintf(" %35s %s a direct numeric literal.", t, fl))
@printf("%35s %s a direct numeric literal.\n", t, fl)
end

View file

@ -1,7 +1,14 @@
sub is-number( $term --> Bool ) {
?($term ~~ /\d/) and $term ~~ Numeric;
sub is-number-w-ws( Str $term --> Bool ) { # treat Falsey strings as numeric
$term.Numeric !~~ Failure;
}
printf "%10s %s\n", "<$_>", is-number( $_ ) for flat
<1 1.2 1.2.3 -6 1/2 12e B17 1.3e+12 1.3e12 -2.6e-3 zero
0x 0xA10 0b1001 0o16 0o18 2+5i>, '1 1 1', '', ' ';
sub is-number-wo-ws( Str $term --> Bool ) { # treat Falsey strings as non-numeric
?($term ~~ / \S /) && $term.Numeric !~~ Failure;
}
say " Coerce Don't coerce";
say ' String whitespace whitespace';
printf "%10s %8s %11s\n",
"<$_>", .&is-number-w-ws, .&is-number-wo-ws for
(|<1 1.2 1.2.3 -6 1/2 12e B17 1.3e+12 1.3e12 -2.6e-3 zero
0x 0xA10 0b1001 0o16 0o18 2+5i>, '1 1 1', '', ' ').map: *.Str;

View file

@ -0,0 +1,16 @@
Sub Main()
Debug.Print Is_Numeric("")
Debug.Print Is_Numeric("-5.32")
Debug.Print Is_Numeric("-51,321 32")
Debug.Print Is_Numeric("123.4")
Debug.Print Is_Numeric("123,4")
Debug.Print Is_Numeric("123;4")
Debug.Print Is_Numeric("123.4x")
End Sub
Private Function Is_Numeric(s As String) As Boolean
Dim Separat As String, Other As String
Separat = Application.DecimalSeparator
Other = IIf(Separat = ",", ".", ",")
Is_Numeric = IsNumeric(Replace(s, Other, Separat))
End Function