SSL Integer.vdmpp
Interaktion und PortierbarkeitVDM
class Integer
functions
staticpublic asString: int -> seq1ofchar
asString(i) == if i < 0 then "-" ^ asStringAux(-i) else
asStringAux(i) ;
staticpublic asStringAux: nat -> seq1ofchar
asStringAux(n) == let r = n mod 10,
q = n div 10 in cases q:
0 -> asChar(r), others -> asStringAux(q) ^ asChar(r) end measure ndiv10;
static ndiv10 : nat +> nat
ndiv10(n) == n div 10;
-- Convert integer to COBOL type number string (like ZZZ9.ZZ). staticpublic asStringZ: seqofchar -> int -> seq1ofchar
asStringZ(cobolStrConversionCommand)(i) == let minusSymbol = '-'in if i < 0 then if cobolStrConversionCommand(1) = minusSymbol then
[minusSymbol] ^ asStringZAux(String`subStr(cobolStrConversionCommand,2,len cobolStrConversionCommand))(-i, true) else
asStringZAux(cobolStrConversionCommand)(-i, true) else if cobolStrConversionCommand(1) = minusSymbol then
asStringZAux(String`subStr(cobolStrConversionCommand,2,len cobolStrConversionCommand))(i, true) else
asStringZAux(cobolStrConversionCommand)(i, true) ;
staticpublic asStringZAux: seqofchar -> nat * bool -> seq1ofchar
asStringZAux(cobolStrConversionCommand)(n, wasZero) == let cobolStrConversionCommandStrLen = len cobolStrConversionCommand,
cobolStrConversionCommandChar = cobolStrConversionCommand(cobolStrConversionCommandStrLen),
cobolStrConversionCommandStr = String`subStr(cobolStrConversionCommand,1,cobolStrConversionCommandStrLen - 1),
r = n mod 10,
q = n div 10,
isZero = r = 0 and wasZero and q <> 0 in cases cobolStrConversionCommandStr:
[] -> asCharZ(cobolStrConversionCommandChar)(r, isZero), others ->
asStringZAux(cobolStrConversionCommandStr)(q, isZero) ^
asCharZ(cobolStrConversionCommandChar)(r, isZero) end; --measure length;
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 ist noch experimentell.