Alldefinitionsareexplicitandexecutable.
*/ module Numeric importsfromSeqall exportsfunctions differBy: real * real * real +> bool;
formatNat: nat +> seq1ofchar;
decodeNat: seq1ofchar +> nat;
fromChar: char +> nat;
toChar: nat +> char;
zeroPad: nat * nat1 +> seq1ofchar;
min: real * real +> real;
max: real * real +> real;
less: real * real +> bool;
leq: real * real +> bool;
grtr: real * real +> bool;
geq: real * real +> bool;
add: real * real +> real;
mult: real * real +> real
definitions
values
DIGITS:seqofchar = "0123456789";
functions
-- Do two numerics differ by at least a specified value.
differBy: real * real * real +> bool
differBy(x, y, delta) == abs (x-y) >= delta pre delta > 0;
-- Format a natural number as a string of digits.
formatNat: nat +> seq1ofchar
formatNat(n) == if n < 10 then [toChar(n)] else formatNat(n div10) ^ formatNat(n mod10) measure size1;
-- Create a natural number from a sequence of digit characters.
decodeNat: seq1ofchar +> nat
decodeNat(s) == cases s:
[c] -> fromChar(c),
u^[c] -> 10*decodeNat(u)+fromChar(c) end measure size2;
-- Convert a character digit to the corresponding natural number.
fromChar: char +> nat
fromChar(c) == Seq`indexOf[char](c,DIGITS)-1 pre c insetelems DIGITS post toChar(RESULT) = c;
-- Convert a numeric digit to the corresponding character.
toChar: nat +> char
toChar(n) == DIGITS(n+1) pre n <= 9; --post fromChar(RESULT) = n
-- Format a natural number as a string with leading zeros up to a specified length.
zeroPad: nat * nat1 +> seq1ofchar
zeroPad(n,w) == Seq`padLeft[char](formatNat(n),'0',w);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.