(compilation "-- -std=c11 -pedantic-errors -Werror") (input) (output "unsigned: 4294967295 18446744073709551615 4294967295" "widths: 1 1 1" "a float stays a float: 1" "radix with suffix: 255 5" "by magnitude: 4000000000 18446744073709551615" "hex floats: 12 0.25 1") (return 0) ;;; A number is written the way C writes it, suffix included, and `_' ;;; takes the type C gives it: the suffix's, or for none the first type ;;; wide enough to hold it. (include stdio.h) (pub fn main () int (var u _ 1u) (var ull _ 1ULL) (printf "unsigned: %u %llu %u\n" (- u 2) (- ull 2) -1u) (var l _ 10L) (var f _ 1.5f) (var ld _ 0.1L) (printf "widths: %d %d %d\n" (== (sizeof l) (sizeof long)) (== (sizeof f) (sizeof float)) (== (sizeof ld) (sizeof (long double)))) ;; the float nearest 0.1 is not the double nearest it (var tenth-f _ 0.1f) (var tenth _ 0.1) (printf "a float stays a float: %d\n" (!= tenth-f tenth)) (printf "radix with suffix: %u %u\n" 0xFFu 0b101u) (var big _ 4000000000) (var mask _ 0xFFFFFFFFFFFFFFFF) (printf "by magnitude: %lld %llu\n" big mask) ;; a double's own digits, which no decimal has to round to (var twelve _ 0x1.8p3) (var quarter _ 0x1p-2f) (printf "hex floats: %g %g %d\n" twelve quarter (== (sizeof quarter) (sizeof float))) (return 0))