| 1 | (* MIN(T) and MAX(T), the smallest and the largest value of each integer |
| 2 | type (report section 6.1), untyped constants: in a constant, in |
| 3 | arithmetic of their own, and given to each type. MAX(U64) and |
| 4 | MAX(UINT) are above the largest I64. *) |
| 5 | module Limits; |
| 6 | import Out; |
| 7 | |
| 8 | const |
| 9 | Byte = MAX(U8) + 1; (* untyped: no wrap at 255 *) |
| 10 | Span = MAX(I16) - MIN(I16); |
| 11 | All = MAX(U64); |
| 12 | |
| 13 | var |
| 14 | i8: I8; i16: I16; i32: I32; i64: I64; int: INT; |
| 15 | u8: U8; u16: U16; u32: U32; u64: U64; uint: UINT; |
| 16 | |
| 17 | proc main*; |
| 18 | begin |
| 19 | Out.int(MIN(I8)); Out.str(" "); Out.int(MAX(I8)); Out.ln; |
| 20 | Out.int(MIN(I16)); Out.str(" "); Out.int(MAX(I16)); Out.ln; |
| 21 | Out.int(MIN(I32)); Out.str(" "); Out.int(MAX(I32)); Out.ln; |
| 22 | Out.int(MIN(I64)); Out.str(" "); Out.int(MAX(I64)); Out.ln; |
| 23 | Out.int(MIN(INT)); Out.str(" "); Out.int(MAX(INT)); Out.ln; |
| 24 | Out.int(MIN(U8)); Out.str(" "); Out.int(MAX(U8)); Out.ln; |
| 25 | Out.int(MIN(U16)); Out.str(" "); Out.int(MAX(U16)); Out.ln; |
| 26 | Out.int(MIN(U32)); Out.str(" "); Out.int(MAX(U32)); Out.ln; |
| 27 | Out.int(MIN(U64)); Out.str(" "); Out.hex(MAX(U64), 16); Out.ln; |
| 28 | Out.int(MIN(UINT)); Out.str(" "); Out.hex(U64(MAX(UINT)), 16); Out.ln; |
| 29 | Out.int(Byte); Out.str(" "); Out.int(Span); Out.str(" "); Out.hex(All, 16); Out.ln; |
| 30 | (* each into its own type, and one past it wraps *) |
| 31 | i8 := MAX(I8); i16 := MIN(I16); i32 := MAX(I32); i64 := MIN(I64); int := MAX(INT); |
| 32 | u8 := MAX(U8); u16 := MAX(U16); u32 := MAX(U32); u64 := MAX(U64); uint := MAX(UINT); |
| 33 | INC(i8); DEC(i16); INC(i32); DEC(i64); INC(int); |
| 34 | INC(u8); INC(u16); INC(u32); INC(u64); INC(uint); |
| 35 | Out.int(I64(i8)); Out.str(" "); Out.int(I64(i16)); Out.str(" "); Out.int(I64(i32)); Out.str(" "); |
| 36 | Out.int(i64); Out.str(" "); Out.int(int); Out.ln; |
| 37 | Out.int(I64(u8)); Out.str(" "); Out.int(I64(u16)); Out.str(" "); Out.int(I64(u32)); Out.str(" "); |
| 38 | Out.hex(u64, 1); Out.str(" "); Out.hex(U64(uint), 1); Out.ln; |
| 39 | end; |
| 40 | |
| 41 | end Limits. |