unleashed / const_fixedp Goto Github PK
View Code? Open in Web Editor NEWA const type for fixed point arithmetic in Rust.
License: Apache License 2.0
A const type for fixed point arithmetic in Rust.
License: Apache License 2.0
The num
crate contains several interesting traits which look useful for both making the internal representation of FixedP
generic (either directly or via requirements on precision) and for exposing methods on that struct to other users. For example, there are traits to expose the checked addition/subtratcion/multiplication/division which could be useful for external generic code using those traits.
Currently an u64
is used internally by FixedP
to represent the integral and fractional parts of a fixed point value.
Specifying requirements on the integral part does not necessarily mean the inner type must change, but it means some further checks would be needed, similar to what is now being tested now given the precision of the fractional part.
As part of that requirement we might want to choose a bigger or smaller internal representation, for which we would end up with a generic parameter that would either need to be computed or accepted as a type parameter.
Currently one cannot have default type parameters along const type parameters on stable Rust, so specifying an internal type would take a hit on ergonomics. When/if this is resolved it would be interesting to take a look at this option.
This is because a conflicting blanket impl exists already for the case where Q == P (ie. both types are exactly the same, with same precision const type parameter).
This is a reminder that perhaps at some point we should be able to specify that we want TryFrom
for such cases where Q != P. This is currently solved by providing an inherent method to this end, but has the problem that it can't be used in generic code using TryFrom
.
Perhaps at some point specialization can be used to make the blanket impl the one used when Q == P only?
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.