Define a primitive data type: Difference between revisions

m
→‎[[Defining Primitive Data Types#ALGOL 68]]: Add the LWB and UPB operators for RANGEs
m (→‎{{header|Java}}: Incorrect use of incorrect template)
m (→‎[[Defining Primitive Data Types#ALGOL 68]]: Add the LWB and UPB operators for RANGEs)
Line 16:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
<!-- Note: I cannot use <lang=algol> here because algol support UTF-8 characters ÷×≤≥↑ etc, and some code is COMMENTED out, sorry -->
# assume max negative int <= ABS - max negative int #
INT max bounded = ( LENG max int * max int > long max int | ENTIER sqrt(max int) | max int );
MODE RANGE = STRUCT(INT lwb, upb);
MODE BOUNDED = STRUCT(INT value, RANGE range);
FORMAT bounded repr = $g"["g(-0)":"g(-0)"]"$;
# Define some useful operators for looping over ranges #
OP LWB = (RANGE range)INT: lwb OF range,
UPB = (RANGE range)INT: upb OF range,
LWB = (BOUNDED bounded)INT: lwb OF range OF bounded,
UPB = (BOUNDED bounded)INT: upb OF range OF bounded;
PROC raise exception = ([]STRING args)VOID: (
Line 154 ⟶ 159:
--> COMMENT
# Test: #
RANGE range = RANGE(0, 10000);
Line 164 ⟶ 169:
BOUNDED a, b := 0 OVER range;
FOR step FROM 4 BY 4 TO UPB range DO # something for pythagoras #
b := b + step OVER range;
a := ENTIER sqrt( 1.5 + 2 * value OF b ) OVER range OF b;