rustc_codegen_clr
rustc_codegen_clr copied to clipboard
Feedback: Simpler Float-to-Integer conversion
While reading https://fractalfir.github.io/generated_html/rustc_codegen_clr_v0_1_1.html I noticed a section on float to integer conversions.
As of .NET 8, all numeric types implement INumberBase<TSelf>
interface.
It exposes the following members:
partial interface INumberBase<TSelf>
{
static TSelf CreateChecked<TOther>(TOther value) where TOther : INumberBase<TOther>;
static TSelf CreateSaturating<TOther>(TOther value) where TOther : INumberBase<TOther>;
static TSelf CreateTruncating<TOther>(TOther value) where TOther : INumberBase<TOther>;
}
Making the following code valid:
var f32 = 257.45f;
var u8 = byte.CreateSaturating(f32);
These can be targeted for numeric conversions of desired behavior instead, and should they receive further optimizations, these improvements would carry over to this project.
p.s.: on dead code elimination - .NET has built-in trimmer/linker which can prune unreachable members, including statics. But if you're aware of it and want to implement the logic separately, then apologies for the spam. All in all very impressive project, keep up good work and thank you.