|
24 | 24 | +architect yegor256@gmail.com |
25 | 25 | +home https://github.com/objectionary/eo |
26 | 26 | +package org.eolang |
27 | | -+rt jvm org.eolang:eo-runtime:0.50.2 |
| 27 | ++rt jvm org.eolang:eo-runtime:0.51.3 |
28 | 28 | +rt node eo2js-runtime:0.0.0 |
29 | | -+version 0.50.2 |
| 29 | ++version 0.51.3 |
30 | 30 |
|
31 | 31 | # The object encapsulates a chain of bytes, adding a few |
32 | 32 | # convenient operations to it. Objects like `int`, `string`, |
|
35 | 35 | data > @ |
36 | 36 | $ > as-bytes |
37 | 37 | eq 01- > as-bool |
38 | | - |
39 | 38 | # Turn this chain of eight bytes into a number. |
40 | 39 | # If there are less or more than eight bytes, there will |
41 | 40 | # be an error returned. |
42 | | - [] > as-number |
43 | | - if. > @ |
44 | | - eq nan.as-bytes |
45 | | - nan |
| 41 | + if. > as-number |
| 42 | + eq nan.as-bytes |
| 43 | + nan |
| 44 | + if. |
| 45 | + eq positive-infinity.as-bytes |
| 46 | + positive-infinity |
46 | 47 | if. |
47 | | - eq positive-infinity.as-bytes |
48 | | - positive-infinity |
| 48 | + eq negative-infinity.as-bytes |
| 49 | + negative-infinity |
49 | 50 | if. |
50 | | - eq negative-infinity.as-bytes |
51 | | - negative-infinity |
52 | | - if. |
53 | | - size.eq 8 |
54 | | - number ^ |
55 | | - error |
56 | | - sprintf |
57 | | - "Can't convert non 8 length bytes to a number, bytes are %x" |
58 | | - * ^ |
| 51 | + size.eq 8 |
| 52 | + number $ |
| 53 | + error |
| 54 | + sprintf |
| 55 | + "Can't convert non 8 length bytes to a number, bytes are %x" |
| 56 | + * $ |
| 57 | + # Turn this chain of eight bytes into a i64 number. |
| 58 | + # If there are less or more than eight bytes, there will |
| 59 | + # be an error returned. |
| 60 | + if. > as-i64 |
| 61 | + size.eq 8 |
| 62 | + i64 $ |
| 63 | + error |
| 64 | + sprintf |
| 65 | + "Can't convert non 8 length bytes to i64, bytes are %x" |
| 66 | + * $ |
| 67 | + # Turn this chain of four bytes into a i32 number. |
| 68 | + # If there are less or more than four bytes, there will |
| 69 | + # be an error returned. |
| 70 | + if. > as-i32 |
| 71 | + size.eq 4 |
| 72 | + i32 $ |
| 73 | + error |
| 74 | + sprintf |
| 75 | + "Can't convert non 4 length bytes to i32, bytes are %x" |
| 76 | + * $ |
| 77 | + # Turn this chain of two bytes into a i16 number. |
| 78 | + # If there are less or more than two bytes, there will |
| 79 | + # be an error returned. |
| 80 | + if. > as-i16 |
| 81 | + size.eq 2 |
| 82 | + i16 $ |
| 83 | + error |
| 84 | + sprintf |
| 85 | + "Can't convert non 2 length bytes to i16, bytes are %x" |
| 86 | + * $ |
59 | 87 |
|
60 | 88 | # Equals to another object. |
61 | 89 | # A condition where two objects have the same value or content. |
|
68 | 96 | # Represents a sub-sequence inside the current one. |
69 | 97 | [start len] > slice /org.eolang.bytes |
70 | 98 |
|
71 | | - # Turn this chain of eight bytes into a i64 number. |
72 | | - # If there are less or more than eight bytes, there will |
73 | | - # be an error returned. |
74 | | - [] > as-i64 |
75 | | - if. > @ |
76 | | - size.eq 8 |
77 | | - i64 ^ |
78 | | - error |
79 | | - sprintf |
80 | | - "Can't convert non 8 length bytes to i64, bytes are %x" |
81 | | - * ^ |
82 | | - |
83 | | - # Turn this chain of four bytes into a i32 number. |
84 | | - # If there are less or more than four bytes, there will |
85 | | - # be an error returned. |
86 | | - [] > as-i32 |
87 | | - if. > @ |
88 | | - size.eq 4 |
89 | | - i32 ^ |
90 | | - error |
91 | | - sprintf |
92 | | - "Can't convert non 4 length bytes to i32, bytes are %x" |
93 | | - * ^ |
94 | | - |
95 | | - # Turn this chain of two bytes into a i16 number. |
96 | | - # If there are less or more than two bytes, there will |
97 | | - # be an error returned. |
98 | | - [] > as-i16 |
99 | | - if. > @ |
100 | | - size.eq 2 |
101 | | - i16 ^ |
102 | | - error |
103 | | - sprintf |
104 | | - "Can't convert non 2 length bytes to i16, bytes are %x" |
105 | | - * ^ |
106 | | - |
107 | 99 | # Calculate the bitwise and operation. |
108 | 100 | [b] > and /org.eolang.bytes |
109 | 101 |
|
|
0 commit comments