Greater than: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Greater than
| Old | New | Line | |
|---|---|---|---|
| 1 | + | <div style="float:right; margin: 0 20px 10px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;"> | |
| 2 | + | ||
| 3 | + | \> | |
| 4 | + | ||
| 5 | + | </div> | |
| 6 | + | ||
| 7 | + | In [[ASCII]], the character code decimal `62` (or [[Hexadecimal|hexadecimal]] `3E`) is defined to be `>` (greater-than sign). | |
| 8 | + | ||
| 9 | + | ## comparison operator | |
| 10 | + | ||
| 11 | + | ### true greater than | |
| 12 | + | ||
| 13 | + | 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 | + | ||
| 15 | + | ``` pascal | |
| 16 | + | program comparisonDemo(input, output, stderr); | |
| 17 | + | ||
| 18 | + | type | |
| 19 | + | size = (tiny, small, medium, large, huge); | |
| 20 | + | ||
| 21 | + | var | |
| 22 | + | n, m: longint; | |
| 23 | + | c, d: char; | |
| 24 | + | ||
| 25 | + | begin | |
| 26 | + | // of course, integers can be compared | |
| 27 | + | n := 2; | |
| 28 | + | m := -2; | |
| 29 | + | ||
| 30 | + | if n > m then | |
| 31 | + | begin | |
| 32 | + | writeLn(n, ' > ', m); | |
| 33 | + | end; | |
| 34 | + | ||
| 35 | + | // also enumerative types can be ordered | |
| 36 | + | if huge > medium then | |
| 37 | + | begin | |
| 38 | + | writeLn('huge is greater than medium'); | |
| 39 | + | end; | |
| 40 | + | ||
| 41 | + | // but the constants true and false are also comparable | |
| 42 | + | if true > false then | |
| 43 | + | begin | |
| 44 | + | writeLn('true is greater than false'); | |
| 45 | + | end; | |
| 46 | + | ||
| 47 | + | // characters stay in a relation to each other, too | |
| 48 | + | // (result depends on the used character set) | |
| 49 | + | c := 'a'; | |
| 50 | + | d := 'Z'; | |
| 51 | + | ||
| 52 | + | if c > d then | |
| 53 | + | begin | |
| 54 | + | writeLn(c, ' > ', d); | |
| 55 | + | end; | |
| 56 | + | end. | |
| 57 | + | ``` | |
| 58 | + | ||
| 59 | + | All ordinal types can be compared to values of the same type. Integers can be compared to any integer. | |
| 60 | + | ||
| 61 | + | ``` pascal | |
| 62 | + | program comparisonSignedDemo(input, output, stderr); | |
| 63 | + | ||
| 64 | + | var | |
| 65 | + | n: int64; | |
| 66 | + | m: qword; | |
| 67 | + | ||
| 68 | + | begin | |
| 69 | + | n := -1; // n stored as %111...111 | |
| 70 | + | m := 2; // m stored as %000...010 | |
| 71 | + | ||
| 72 | + | // signed comparison | |
| 73 | + | if n > m then | |
| 74 | + | begin | |
| 75 | + | writeLn(n, ' > ', m); | |
| 76 | + | end; | |
| 77 | + | ||
| 78 | + | // "unsigned" comparison | |
| 79 | + | if qword(n) > m then | |
| 80 | + | begin | |
| 81 | + | writeLn('qword(', n, ') > ', m); | |
| 82 | + | end; | |
| 83 | + | end. | |
| 84 | + | ``` | |
| 85 | + | ||
| 86 | + | ### greater than or equal to | |
| 87 | + | ||
| 88 | + | 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 | + | ||
| 90 | + | ## bit shift operator | |
| 91 | + | ||
| 92 | + | Two consecutive greater-than signs `>>` act as the [[Shr|shr operator]]. | |
| 93 | + | ||
| 94 | + | ## template list | |
| 95 | + | ||
| 96 | + | In [[Generics|generic type]] definitions the template list is delimited by a closing `>`. | |
| 97 | + | ||
| 98 | + | --- | |
| 99 | + | *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).* |
