Missing arithmetic operators #761
Conversation
…ypes, so now implement them anywhere will be more easy.
Test Results (datex_macros)14 tests 14 ✅ 0s ⏱️ Results for commit 9b6481e. ♻️ This comment has been updated with latest results. |
Test Results (no_std)218 tests 218 ✅ 6s ⏱️ Results for commit 9b6481e. ♻️ This comment has been updated with latest results. |
Test Results (std)233 tests 233 ✅ 6s ⏱️ Results for commit 9b6481e. ♻️ This comment has been updated with latest results. |
Test Results (no_std_full)806 tests 806 ✅ 10s ⏱️ Results for commit 9b6481e. ♻️ This comment has been updated with latest results. |
Test Results (std_full)825 tests 825 ✅ 12s ⏱️ Results for commit 9b6481e. ♻️ This comment has been updated with latest results. |
|
| Branch | feat/operator-mul-div |
| Testbed | ubuntu-latest |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result nanoseconds (ns) (Result Δ%) | Upper Boundary nanoseconds (ns) (Limit %) |
|---|---|---|---|
| dxb to json/test1.json | 📈 view plot 🚷 view threshold | 68,683.00 ns(+0.67%)Baseline: 68,228.70 ns | 110,877.17 ns (61.95%) |
| dxb to json/test2.json | 📈 view plot 🚷 view threshold | 18,542,000.00 ns(+14.55%)Baseline: 16,187,100.00 ns | 31,137,986.22 ns (59.55%) |
| dxb to runtime value/test1.json | 📈 view plot 🚷 view threshold | 39,526.00 ns(-0.59%)Baseline: 39,760.60 ns | 63,909.50 ns (61.85%) |
| dxb to runtime value/test2.json | 📈 view plot 🚷 view threshold | 10,750,000.00 ns(-2.45%)Baseline: 11,019,700.00 ns | 17,035,511.13 ns (63.10%) |
| json to dxb/test1.json | 📈 view plot 🚷 view threshold | 64,948.00 ns(-84.42%)Baseline: 416,940.80 ns | 1,276,323.07 ns (5.09%) |
| json to dxb/test2.json | 📈 view plot 🚷 view threshold | 20,687,000.00 ns(-83.61%)Baseline: 126,231,300.00 ns | 365,090,360.46 ns (5.67%) |
| json to runtime value datex auto static detection/test1.json | 📈 view plot 🚷 view threshold | 92,192.00 ns(-78.83%)Baseline: 435,458.10 ns | 1,257,780.93 ns (7.33%) |
| json to runtime value datex auto static detection/test2.json | 📈 view plot 🚷 view threshold | 30,058,000.00 ns(-77.86%)Baseline: 135,757,600.00 ns | 362,440,556.27 ns (8.29%) |
| json to runtime value datex forced static/test1.json | 📈 view plot 🚷 view threshold | 77,101.00 ns(-81.62%)Baseline: 419,480.70 ns | 1,275,110.77 ns (6.05%) |
| json to runtime value datex forced static/test2.json | 📈 view plot 🚷 view threshold | 25,905,000.00 ns(-79.48%)Baseline: 126,245,800.00 ns | 374,294,689.83 ns (6.92%) |
| json to runtime value datex/test1.json | 📈 view plot 🚷 view threshold | 111,770.00 ns(-74.94%)Baseline: 445,946.00 ns | 1,248,144.03 ns (8.95%) |
| json to runtime value datex/test2.json | 📈 view plot 🚷 view threshold | 32,547,000.00 ns(-76.23%)Baseline: 136,913,300.00 ns | 372,400,041.62 ns (8.74%) |
| json to runtime value json_syntax/test1.json | 📈 view plot 🚷 view threshold | 11,752.00 ns(-32.80%)Baseline: 17,487.30 ns | 30,151.27 ns (38.98%) |
| json to runtime value json_syntax/test2.json | 📈 view plot 🚷 view threshold | 4,231,600.00 ns(-26.92%)Baseline: 5,790,340.00 ns | 9,270,799.74 ns (45.64%) |
| json to runtime value serde_json/test1.json | 📈 view plot 🚷 view threshold | 4,662.60 ns(-20.10%)Baseline: 5,835.67 ns | 8,058.23 ns (57.86%) |
| json to runtime value serde_json/test2.json | 📈 view plot 🚷 view threshold | 1,687,600.00 ns(-15.78%)Baseline: 2,003,850.00 ns | 2,583,725.29 ns (65.32%) |
| runtime init | 📈 view plot 🚷 view threshold | 0.31 ns(-100.00%)Baseline: 101,757.03 ns | 1,033,065.87 ns (0.00%) |
| runtime value to dxb/test1.json | 📈 view plot 🚷 view threshold | 4,055.20 ns(+1.03%)Baseline: 4,014.01 ns | 8,296.46 ns (48.88%) |
| runtime value to dxb/test2.json | 📈 view plot 🚷 view threshold | 1,143,200.00 ns(+5.92%)Baseline: 1,079,335.00 ns | 2,314,164.21 ns (49.40%) |
| runtime value to json datex/test1.json | 📈 view plot 🚷 view threshold | 72,462.00 ns(-1.02%)Baseline: 73,210.30 ns | 121,363.17 ns (59.71%) |
| runtime value to json datex/test2.json | 📈 view plot 🚷 view threshold | 19,603,000.00 ns(+11.75%)Baseline: 17,541,900.00 ns | 34,634,050.54 ns (56.60%) |
| runtime value to json json_syntax/test1.json | 📈 view plot 🚷 view threshold | 6,224.20 ns(-33.98%)Baseline: 9,427.65 ns | 15,551.86 ns (40.02%) |
| runtime value to json json_syntax/test2.json | 📈 view plot 🚷 view threshold | 2,639,600.00 ns(-34.33%)Baseline: 4,019,720.00 ns | 6,527,691.85 ns (40.44%) |
| runtime value to json serde_json/test1.json | 📈 view plot 🚷 view threshold | 1,587.50 ns(-37.80%)Baseline: 2,552.38 ns | 5,203.71 ns (30.51%) |
| runtime value to json serde_json/test2.json | 📈 view plot 🚷 view threshold | 480,180.00 ns(-44.64%)Baseline: 867,309.00 ns | 1,813,101.71 ns (26.48%) |
… 'mod' operator in Integer
|
Test (datex-macros) / Test (datex-macros) (pull_request) |
…mmit I will all other Math op tsame fast
…logical operators in DATEX
…adding a bit docs and some other things
| @@ -1,3 +1,30 @@ | |||
| //! [`Integer`] is precise number that can be used for very fast and cheep Math operations that doesnt need | |||
There was a problem hiding this comment.
Avoid backticks for linked modules. Prefer [Integer] over [`Integer`]
| } | ||
|
|
||
| #[test] | ||
| fn doc_test() { |
| } | ||
|
|
||
| impl Mul for TypedInteger { | ||
| type Output = Option<TypedInteger>; |
There was a problem hiding this comment.
Use wrapped instead, and not return a option but TypedInteger
| TypedInteger::I8(v1) => TypedInteger::I8(match rhs { | ||
| TypedInteger::I8(v2) => v1.checked_mul(v2)?, | ||
| TypedInteger::I16(v2) => { | ||
| i8::try_from((v1 as i16).checked_mul(v2)?).ok()? |
There was a problem hiding this comment.
move to checked_mul and implement a non fallible wrapped_mul
|
|
||
| impl Neg for Value { | ||
| impl Mul for Value { | ||
| type Output = Result<Value, ValueError>; |
There was a problem hiding this comment.
Should not be an error
There was a problem hiding this comment.
Error where? Or ths microsoft or I am dumb
There was a problem hiding this comment.
impl Mul for Value {
type Output = Result<Value, ValueError>; // here it should be Value and not Result
as multiplication can never fail, we can transition the Result<X, Y> to X.
Only Rem and Div might fail, as divisions by zero for integers can occur. For decimals we never expect errors for all arithmentic operators.
…ion will not fail this time
…ible with easy implementation for new Types
…cture, also adding a few methods for Map
| @@ -61,84 +73,183 @@ pub enum InstructionCode { | |||
|
|
|||
| To allow for serialization of the new instruction and it's potential payload, it | |||
| might be necessary to add a new entry to the `Instruction` enum in the | |||
There was a problem hiding this comment.
new entry to either RegularInstruction enum or TypeInstruction enum, not to Instruction enum directly
| might be necessary to add a new entry to the `Instruction` enum in the | ||
| [`datex-core/src/global/protocol_structures/instructions.rs`](../../src/global/protocol_structures/instructions.rs) | ||
| file: | ||
| [`/cratesdatex-core/src/global/protocol_structures/instructions.rs`](../../crates/datex-core/src/global/protocol_structures/instructions.rs) |
| ``` | ||
|
|
||
| Is, // New instruction for the `is` operator | ||
| There are two types of `Instruction`, if your `Data Type` or `Data Structure` produces a runtime value then its a `RegularInstruction` e.g. |
There was a problem hiding this comment.
The distinction is not completely correct. Both Type Instructions and Regular Instructions can produce "runtime values". The distinction is more between "normal" values and "type space" values.
E.g. when defining a type with
type example = integer | text
the right hand side is represented by type instructions. But when defining a normal variable with
var example = "example";
the right hand side are regular instructions
| the [`datex-core/src/compiler/parser.rs`](../../src/compiler/ast_parser) module. | ||
| The parser is responsible for converting the sequence of tokens recognized by | ||
| the lexer into an Abstract Syntax Tree (AST). | ||
| If you want to understand exactly why `push_next_regular(2)` and how does it work you can either look for something that is close for your new syntax, for example you add something like `Array`, then look at `List`, or try to read each function that is used in `InstructionCode` creating to use 100% correct one |
There was a problem hiding this comment.
I think this can be explained in the guide.
The push_next_regular just indicated how many additional instructions are guaranteed to follow after the current instruction. So e.g. a list with 3 elements will have the LIST instruction followed by at least 3 more instructions resolving to the 3 elements of the list.
|
|
||
| and add there instruction how your Syntax must be converted in `ValueContainer` | ||
|
|
||
| Again here is `List` example |
There was a problem hiding this comment.
Please also specify the name of the function where this mapping must be added
| Token::RightCurly => Some("}"), | ||
| Token::LeftAngle => Some("<"), | ||
| Token::RightAngle => Some(">"), | ||
| Token::SetOpen => Some("<|"), |
There was a problem hiding this comment.
Note: Set will probably not have a custom syntax, it will just be written as Set(...)
There was a problem hiding this comment.
100% it will not have a custom syntax, I just wanted to try to add something with custom Token, and I know and understand that special Token for Set is not the best idea

…ypes, so now implement them anywhere will be more easy.