Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -0,0 +1,12 @@
(defun string-valid-number-p (str)
"Test if STR is a numeric string.
Eliminate strings with commas in them because ELisp numbers do
not contain commas. Then check if remaining strings would be
valid ELisp numbers if the quotation marks were removed."
(and
;; no comma in string, because ELisp numbers do not have commas
;; we need to eliminate any string with a comma, because the
;; numberp function below will not weed out commas
(not (string-match-p "," str))
;; no errors from numberp function testing if a number
(ignore-errors (numberp (read str)))))

View file

@ -0,0 +1,17 @@
(setq valid-strings '("3" "0" "-0" "2." "1000" "-4" "-5." "6.2" "-8.45" "+15e2" "-15e2" "#b101100" "#o54" "#x2c" "1500.0" "#24r1k" "3"))
(setq invalid-strings '("3cat" "1,000" "5.6.7" "cat3" "def" "zero"))
(with-current-buffer (pop-to-buffer "my-test")
(erase-buffer)
(insert "Test for valid strings:\n")
(dolist (test-string valid-strings)
(let ((test-result))
(setq test-result (string-valid-number-p test-string))
(insert (format "%-8s - %s \n" test-string test-result))))
(insert "\n" "\n")
(insert "Test for invalid strings:\n")
(dolist (test-string invalid-strings)
(let ((test-result))
(setq test-result (string-valid-number-p test-string))
(insert (format "%-5s - %s \n" test-string test-result)))))

View file

@ -0,0 +1,11 @@
function IsNumeric(s: string): boolean;
begin
var i: integer;
Result := integer.TryParse(s,i)
end;
begin
var s := '123';
if IsNumeric(s) then
Print('string is numeric')
end.

View file

@ -0,0 +1,34 @@
use std::str::FromStr;
fn parsable<T: FromStr>(s: &str) -> bool {
s.parse::<T>().is_ok()
}
fn main() {
let test_cases = [
"142857",
"3.14",
"not of this earth!"
];
let types: &[(&str, fn(&str) -> bool)] = &[
("i32", parsable::<i32> as fn(&str) -> bool),
("i64", parsable::<i32> as fn(&str) -> bool),
("i128", parsable::<i32> as fn(&str) -> bool),
("f64", parsable::<f64> as fn(&str) -> bool),
];
println!("");
for &case in &test_cases {
for &(type_name, parse_fn) in types {
println!(
"'{}' {} be parsed as {}",
case,
if parse_fn(case) { "can" } else { "_cannot_" },
type_name
);
}
println!("");
}
}

View file

@ -0,0 +1,32 @@
const std = @import("std");
const stdout = std.io.getStdOut().writer();
fn isNumeric(str: []const u8) bool {
const num = std.mem.trim(u8, str, "\x20");
_ = std.fmt.parseFloat(f64, num) catch return false;
return true;
}
pub fn main() !void {
const s1 = " 123";
const s2 = " +123";
const s3 = " 12.3";
const s4 = "-12.3";
const s5 = "12e-3";
const s6 = "=12-3";
const s7 = "abcde";
const s8 = "12cde";
const s9 = "NaN";
const s10 = "0xFF";
try stdout.print("Is {s} numeric? {}\n", .{ s1, isNumeric(s1) });
try stdout.print("Is {s} numeric? {}\n", .{ s2, isNumeric(s2) });
try stdout.print("Is {s} numeric? {}\n", .{ s3, isNumeric(s3) });
try stdout.print("Is {s} numeric? {}\n", .{ s4, isNumeric(s4) });
try stdout.print("Is {s} numeric? {}\n", .{ s5, isNumeric(s5) });
try stdout.print("Is {s} numeric? {}\n", .{ s6, isNumeric(s6) });
try stdout.print("Is {s} numeric? {}\n", .{ s7, isNumeric(s7) });
try stdout.print("Is {s} numeric? {}\n", .{ s8, isNumeric(s8) });
try stdout.print("Is {s} numeric? {}\n", .{ s9, isNumeric(s9) });
try stdout.print("Is {s} numeric? {}\n", .{ s10, isNumeric(s10) });
}