respitesage / saline Goto Github PK
View Code? Open in Web Editor NEWSaturating arithmetic for Crystal
License: MIT License
Saturating arithmetic for Crystal
License: MIT License
Currently, Saturating
can't be used directly as the argument of Number
arithmetic operations. You have to use Saturating#value
. That seems non-ideal, so I should implement patches on numeric types to allow operations with Saturating
on the right-hand side.
Currently Saturating
doesn't override division operators (they should still work, just without saturating arithmetic), but division by values between 0 and 1 could cause overflow. I expect the addition to match the existing code fairly well.
Currently, Saturating
can only perform operations with Number
types and Saturating
objects with the same generic type. Instead, you should be able to add Saturating(T)
with Saturating(U)
for any T
and U
(and of course the same goes for other operations). In theory, this should be as easy as adding forall U
and updating method definitions correspondingly.
It would be nice to have saturating arithmetic with saturation boundaries wherever you want. If, for example, you wanted to saturate at a much lower upper boundary than existing types (e.g. 30) or had some weird desired lower and upper boundaries (e.g. [32..210]), it would be nice to have types that would just act how you wanted instead of needing checks everywhere.
So far, I'm thinking that this could be accomplished by having another struct or class like so
Clamped(T,B,U)
where T
is the value type, like right now, B
is a numeric lower bound, and U
is a numeric upper bound. In theory, you could probably implement the existing Saturating
struct as one of these new types, but structs can't inherit from non-abstract structs... It's worth thinking about.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.