Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of an attribute for properties with System.Double Type to indicate the level of precision? #12

Open
marlond18 opened this issue Apr 1, 2021 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@marlond18
Copy link

No description provided.

@diegofrata diegofrata added enhancement New feature or request help wanted Extra attention is needed labels Apr 1, 2021
@diegofrata
Copy link
Owner

That's interesting and definitely could be added for floating number types!

@diegofrata
Copy link
Owner

Could probably call it PrecisionEquality

@diegofrata
Copy link
Owner

diegofrata commented Jun 3, 2021

Version 2.2.0 now supports the attribute CustomEquality, which can be used to bridge any specific case not built into the library, including comparing doubles.

I will leave this issue open however, because I think this should be implemented at some point.

@diegofrata diegofrata added the good first issue Good for newcomers label Feb 2, 2024
@espenrl
Copy link

espenrl commented Feb 7, 2024

I was experimenting with an implementation using generics to target any floating point type using generic attributes and generic math with IFloatingPoint<T>. Though that would be restricted to .NET 7 and newer (with C# 11 compiler).

[GeneratedCode("Generator.Equals", "1.0.0.0")]
[Conditional("GENERATOR_EQUALS")]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class PrecisionEqualityAttribute<T> : Attribute
    where T : IFloatingPoint<T>
{
    public T Precision { get; }

    public PrecisionEqualityAttribute(T precision)
    {
        Precision = precision;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants