Greater than: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | 1 | \> | |
| 4 | - | ||
| 5 | - | ||
| 6 | 2 | ||
| 7 | 3 | In [[ASCII]], the character code decimal `62` (or [[Hexadecimal|hexadecimal]] `3E`) is defined to be `>` (greater-than sign). | |
| 8 | 4 | ||
| 9 | 5 | ## comparison operator | |
| 10 | 6 | ||
| 11 | 7 | ### true greater than | |
| 12 | 8 | ||
| 13 | 9 | The greater than symbol `>` is used to compare whether the value on the left side of the symbol, exceeds that of the value to the right side of the symbol. The [[expression]] results in a [[Boolean|boolean value]]. | |
| 14 | 10 | ||
| 15 | 11 | ``` pascal | |
| 16 | 12 | program comparisonDemo(input, output, stderr); | |
| 17 | 13 | ||
| 18 | 14 | type | |
| 19 | 15 | size = (tiny, small, medium, large, huge); | |
| 20 | 16 | ||
| 21 | 17 | var | |
| 22 | 18 | n, m: longint; | |
| 23 | 19 | c, d: char; | |
| 24 | 20 | ||
| 25 | 21 | begin | |
| 26 | 22 | // of course, integers can be compared | |
| 27 | 23 | n := 2; | |
| 28 | 24 | m := -2; | |
| 29 | 25 | ||
| 30 | 26 | if n > m then | |
| 31 | 27 | begin | |
| 32 | 28 | writeLn(n, ' > ', m); | |
| 33 | 29 | end; | |
| 34 | 30 | ||
| 35 | 31 | // also enumerative types can be ordered | |
| 36 | 32 | if huge > medium then | |
| 37 | 33 | begin | |
| 38 | 34 | writeLn('huge is greater than medium'); | |
| 39 | 35 | end; | |
| 40 | 36 | ||
| 41 | 37 | // but the constants true and false are also comparable | |
| 42 | 38 | if true > false then | |
| 43 | 39 | begin | |
| 44 | 40 | writeLn('true is greater than false'); | |
| 45 | 41 | end; | |
| 46 | 42 | ||
| 47 | 43 | // characters stay in a relation to each other, too | |
| 48 | 44 | // (result depends on the used character set) | |
| 49 | 45 | c := 'a'; | |
| 50 | 46 | d := 'Z'; | |
| 51 | 47 | ||
| 52 | 48 | if c > d then | |
| 53 | 49 | begin | |
| 54 | 50 | writeLn(c, ' > ', d); | |
| 55 | 51 | end; | |
| 56 | 52 | end. | |
| 57 | 53 | ``` | |
| 58 | 54 | ||
| 59 | 55 | All ordinal types can be compared to values of the same type. Integers can be compared to any integer. | |
| 60 | 56 | ||
| 61 | 57 | ``` pascal | |
| 62 | 58 | program comparisonSignedDemo(input, output, stderr); | |
| 63 | 59 | ||
| 64 | 60 | var | |
| 65 | 61 | n: int64; | |
| 66 | 62 | m: qword; | |
| 67 | 63 | ||
| 68 | 64 | begin | |
| 69 | 65 | n := -1; // n stored as %111...111 | |
| 70 | 66 | m := 2; // m stored as %000...010 | |
| 71 | 67 | ||
| 72 | 68 | // signed comparison | |
| 73 | 69 | if n > m then | |
| 74 | 70 | begin | |
| 75 | 71 | writeLn(n, ' > ', m); | |
| 76 | 72 | end; | |
| 77 | 73 | ||
| 78 | 74 | // "unsigned" comparison | |
| 79 | 75 | if qword(n) > m then | |
| 80 | 76 | begin | |
| 81 | 77 | writeLn('qword(', n, ') > ', m); | |
| 82 | 78 | end; | |
| 83 | 79 | end. | |
| 84 | 80 | ``` | |
| 85 | 81 | ||
| 86 | 82 | ### greater than or equal to | |
| 87 | 83 | ||
| 88 | 84 | If the greater than symbol is followed by an [[Equal|equal sign]] `>=`, the comparison also results in [[True|true]] if both operands are equal to each other. | |
| 89 | 85 | ||
| 90 | 86 | ## bit shift operator | |
| 91 | 87 | ||
| 92 | 88 | Two consecutive greater-than signs `>>` act as the [[Shr|shr operator]]. | |
| 93 | 89 | ||
| 94 | 90 | ## template list | |
| 95 | 91 | ||
| 96 | 92 | In [[Generics|generic type]] definitions the template list is delimited by a closing `>`. | |
| 97 | 93 | ||
| 98 | 94 | --- | |
| 99 | 95 | *From the Free Pascal wiki, page "Greater than", as it stood on 2022-08-06 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
