FractalFir / FractalFir/rustc_codegen_clr

Feedback: Simpler Float-to-Integer conversion

Open
#39 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2.1k
Forks
55
PR merge metrics
No merged PRs in 30d

Description

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` interface.
It exposes the following members:
```cs
partial interface INumberBase
{
static TSelf CreateChecked(TOther value) where TOther : INumberBase;
static TSelf CreateSaturating(TOther value) where TOther : INumberBase;
static TSelf CreateTruncating(TOther value) where TOther : INumberBase;
}
```
Making the following code valid:
```cs
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](https://github.com/dotnet/runtime/tree/main/src/tools/illink) 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.