Overview
Comment: | Add -[{and,or,xor,shiftLeft,shiftRight}:] to OFNumber. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
a57d46cb3bbb035f94fe1081721d5c98 |
User & Date: | js on 2010-03-13 22:27:08 |
Other Links: | manifest | tags |
Context
2010-03-14
| ||
12:37 | Documentation improvements. check-in: 40523d5535 user: js tags: trunk | |
2010-03-13
| ||
22:27 | Add -[{and,or,xor,shiftLeft,shiftRight}:] to OFNumber. check-in: a57d46cb3b user: js tags: trunk | |
21:27 | Add tests for OFStream. check-in: aa3e784dd8 user: js tags: trunk | |
Changes
Modified src/OFNumber.h from [b4de2a5a33] to [b0f5b934e7].
︙ | ︙ | |||
556 557 558 559 560 561 562 563 564 565 566 567 568 569 | /** * \param num The OFNumber to divide by * \return The OFNumber devided by the specified OFNumber */ - divideBy: (OFNumber*)num; /** * \return The OFNumber increased by one. */ - increase; /** * \return The OFNumber decreased by one. | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | /** * \param num The OFNumber to divide by * \return The OFNumber devided by the specified OFNumber */ - divideBy: (OFNumber*)num; /** * ANDs two OFNumbers, returning a new one. * * Does not work with floating point types! * * \param num The number to AND with. * \return The OFNumber ANDed with the specified OFNumber */ - and: (OFNumber*)num; /** * ORs two OFNumbers, returning a new one. * * Does not work with floating point types! * * \param num The number to OR with. * \return The OFNumber ORed with the specified OFNumber */ - or: (OFNumber*)num; /** * XORs two OFNumbers, returning a new one. * * Does not work with floating point types! * * \param num The number to XOR with. * \return The OFNumber XORed with the specified OFNumber */ - xor: (OFNumber*)num; /** * Bitshifts the OFNumber to the left by the specified OFNumber, returning a new * one. * * Does not work with floating point types! * * \param num The number of bits to shift to the left * \return The OFNumber bitshifted to the left with the specified OFNumber */ - shiftLeft: (OFNumber*)num; /** * Bitshifts the OFNumber to the right by the specified OFNumber, returning a * new one. * * Does not work with floating point types! * * \param num The number of bits to shift to the right * \return The OFNumber bitshifted to the right with the specified OFNumber */ - shiftRight: (OFNumber*)num; /** * \return The OFNumber increased by one. */ - increase; /** * \return The OFNumber decreased by one. |
︙ | ︙ |
Modified src/OFNumber.m from [6467769256] to [ff05eb19c1].
︙ | ︙ | |||
141 142 143 144 145 146 147 | value.float_ o [n asFloat]]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: \ value.double_ o [n asDouble]]; \ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | value.float_ o [n asFloat]]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: \ value.double_ o [n asDouble]]; \ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } #define CALCULATE2(o, n) \ switch (type) { \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: \ value.char_ o [n asChar]]; \ case OF_NUMBER_SHORT: \ return [OFNumber numberWithShort: \ value.short_ o [n asShort]]; \ case OF_NUMBER_INT: \ return [OFNumber numberWithInt: \ value.int_ o [n asInt]]; \ case OF_NUMBER_LONG: \ return [OFNumber numberWithLong: \ value.long_ o [n asLong]]; \ case OF_NUMBER_UCHAR: \ return [OFNumber numberWithUChar: \ value.uchar o [n asUChar]]; \ case OF_NUMBER_USHORT: \ return [OFNumber numberWithUShort: \ value.ushort o [n asUShort]]; \ case OF_NUMBER_UINT: \ return [OFNumber numberWithUInt: \ value.uint o [n asUInt]]; \ case OF_NUMBER_ULONG: \ return [OFNumber numberWithULong: \ value.ulong o [n asULong]]; \ case OF_NUMBER_INT8: \ return [OFNumber numberWithInt8: \ value.int8 o [n asInt8]]; \ case OF_NUMBER_INT16: \ return [OFNumber numberWithInt16: \ value.int16 o [n asInt16]]; \ case OF_NUMBER_INT32: \ return [OFNumber numberWithInt32: \ value.int32 o [n asInt32]]; \ case OF_NUMBER_INT64: \ return [OFNumber numberWithInt64: \ value.int64 o [n asInt64]]; \ case OF_NUMBER_UINT8: \ return [OFNumber numberWithUInt8: \ value.uint8 o [n asUInt8]]; \ case OF_NUMBER_UINT16: \ return [OFNumber numberWithUInt16: \ value.uint16 o [n asUInt16]]; \ case OF_NUMBER_UINT32: \ return [OFNumber numberWithUInt32: \ value.uint32 o [n asUInt32]]; \ case OF_NUMBER_UINT64: \ return [OFNumber numberWithUInt64: \ value.uint64 o [n asUInt64]]; \ case OF_NUMBER_SIZE: \ return [OFNumber numberWithSize: \ value.size o [n asSize]]; \ case OF_NUMBER_SSIZE: \ return [OFNumber numberWithSSize: \ value.ssize o [n asSSize]]; \ case OF_NUMBER_INTMAX: \ return [OFNumber numberWithIntMax: \ value.intmax o [n asIntMax]]; \ case OF_NUMBER_UINTMAX: \ return [OFNumber numberWithUIntMax: \ value.uintmax o [n asUIntMax]]; \ case OF_NUMBER_PTRDIFF: \ return [OFNumber numberWithPtrDiff: \ value.ptrdiff o [n asPtrDiff]]; \ case OF_NUMBER_INTPTR: \ return [OFNumber numberWithIntPtr: \ value.intptr o [n asIntPtr]]; \ case OF_NUMBER_FLOAT: \ case OF_NUMBER_DOUBLE: \ @throw [OFNotImplementedException newWithClass: isa \ selector: _cmd]; \ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } #define CALCULATE3(o) \ switch (type) { \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: value.char_ o]; \ case OF_NUMBER_SHORT: \ return [OFNumber numberWithShort: value.short_ o]; \ case OF_NUMBER_INT: \ return [OFNumber numberWithInt: value.int_ o]; \ |
︙ | ︙ | |||
773 774 775 776 777 778 779 780 781 782 | CALCULATE(*, num) } - divideBy: (OFNumber*)num { CALCULATE(/, num) } - increase { | > > > > > > > > > > > > > > > > > > > > > > > > > | | | 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | CALCULATE(*, num) } - divideBy: (OFNumber*)num { CALCULATE(/, num) } - and: (OFNumber*)num { CALCULATE2(&, num) } - or: (OFNumber*)num { CALCULATE2(|, num) } - xor: (OFNumber*)num { CALCULATE2(^, num) } - shiftLeft: (OFNumber*)num { CALCULATE2(<<, num) } - shiftRight: (OFNumber*)num { CALCULATE2(>>, num) } - increase { CALCULATE3(+ 1) } - decrease { CALCULATE3(- 1) } @end |
Modified tests/OFNumber.m from [eeaf3e0ae9] to [74f86e0a57].
︙ | ︙ | |||
36 37 38 39 40 41 42 43 44 | TEST(@"-[decrease]", [[num decrease] isEqual: [OFNumber numberWithInt32: 123456788]]) TEST(@"-[divideBy:]", [[num divideBy: [OFNumber numberWithInt: 2]] asInt] == 61728394) [pool drain]; } | > > > > > > | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | TEST(@"-[decrease]", [[num decrease] isEqual: [OFNumber numberWithInt32: 123456788]]) TEST(@"-[divideBy:]", [[num divideBy: [OFNumber numberWithInt: 2]] asInt] == 61728394) TEST(@"-[xor:]", [[num xor: [OFNumber numberWithInt: 123456831]] asInt] == 42) TEST(@"-[shiftRight:]", [[num shiftRight: [OFNumber numberWithInt: 8]] asInt] == 482253) [pool drain]; } |