You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So we kind of need to dig into the concept of a number here. Bloblang itself has support for both floats (64 bit) and integers (64 bit signed and also unsigned), and when two numbers are used in arithmetic it is able to make a best attempt at preserving integer based accuracy. For example, if two numbers are multiplied and both are integers then we can return an integer, if one of the numbers is a float then we cast the integer to a float and return a float.
This makes it possible to process integer values but there are also many ways of degrading them into a float. It only makes sense to add a logical shift operator if it's possible for users to know explicitly that certain values are integers of an explicit size. We also need to add documentation that clearly explains what users can expect, since most of the time the data being consumed and produced is JSON, which itself doesn't support large integers.
Originally my intention was to avoid adding bitwise arithmetic for these reasons, but if there's a strong use case for it then there are ways of getting to the point where it's possible. We would need to ensure that foo >> 1 returns a mapping error if foo is not an integer (which can be caught with (foo >> 1).catch(0)).
Before considering this we should add an optional parameter to type where the output number is replaced in favour of explicit int64, uint64 and float64, allowing you to do this if foo.type(true) == "int64" { foo >> 1 }. We should also add a method integer, which would work the same as number except always return an integer.
Finally, we'd need to audit all of the current arithmetic operators and ensure that float degradation can be avoided, right now it's a best attempt that isn't necessarily enforced.
The bloblang processor doesn't seem to parse the "<<"/">>" operator to do logical shifts, any ideias on how to properly do it ?
The text was updated successfully, but these errors were encountered: