RosettaCodeData/Task/Integer-overflow/M2000-Interpreter/integer-overflow.m2000

38 lines
987 B
Plaintext

Long A
Try ok {
A=12121221212121
}
If not ok then Print Error$ 'Overflow Long
Def Integer B
Try ok {
B=1212121212
}
If not ok then Print Error$ ' Overflow Integer
Def Currency C
Try ok {
C=121212121232934392898274327927948
}
If not ok then Print Error$ ' return Overflow Long, but is overflow Currency
Def Decimal D
Try ok {
D=121212121232934392898274327927948
}
If not ok then Print Error$ ' return Overflow Long, but is overflow Decimal
\\ No overflow for unsigned numbers in structs
Structure Struct {
\\ union a1, a2| b
{
a1 as integer
a2 as integer
}
b as long
}
\\ structures are type for Memory Block, or other sttructure
\\ we use Clear to erase internal Memory Block
Buffer Clear DataMem as Struct*20
\\ from a1 we get only the low word
Return DataMem, 0!a2:=0xBBBB, 0!a1:=0xFFFFAAAA
Print Hex$(Eval(DataMem, 0!b))="BBBBAAAA"
Print Eval(DataMem, 0!b)=Eval(DataMem, 0!a2)*0x10000+Eval(DataMem, 0!a1)