Add options to define arithmetic operators separately#30
Merged
Conversation
hadashiA
commented
Aug 17, 2023
hadashiA
commented
Aug 17, 2023
| public static Hp operator -(in Hp x, in Hp y) => new Hp(checked((int)(x.value - y.value))); | ||
| public static Hp operator *(in Hp x, in Hp y) => new Hp(checked((int)(x.value * y.value))); | ||
| public static Hp operator /(in Hp x, in Hp y) => new Hp(checked((int)(x.value / y.value))); | ||
| public static Hp operator +(Hp x, Hp y) => new Hp(checked((int)(x.value + y.value))); |
Contributor
Author
There was a problem hiding this comment.
The in modifiers was removed because it could not comply with interfaces such as INumber<>.
hadashiA
commented
Aug 17, 2023
src/UnitGenerator/SourceGenerator.cs
Outdated
|
|
||
| public static bool TryConvertFromChecked<TOther>(TOther value, out {{unitTypeName}} result) where TOther : INumberBase<TOther> | ||
| { | ||
| throw new NotSupportedException(); |
Contributor
Author
There was a problem hiding this comment.
The methods ofTryConvert* family are in INumberBase<T> but cannot be called because they are protected. I compromised and made it NotSupported....
Please let me know if you have a better way.
Contributor
Author
There was a problem hiding this comment.
Fixed implementation to return false.
System.Numerics.INumber<T>, and more options to specify operators individually.
Member
|
thank you! ok to merge! |
80511ed to
4670481
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
EDIT:
INumber<T>implementation was stopped.IfUnitGenerateOptions.ArithmeticOperatoris specified, make sure that all members conforming toINumber<T>are created by default.This allows UnitOf generated types to take advantage of features supported by Generic math. NET8 or later, for example, LINQ's aggregate would be available.Add extra option
UnitArithmeticOperatorsUnitArithmeticOperatorsenum to allow specifying the individual arithmetic operators to be generated.IAdditionalOperators<>, which was added in .Breaking Changes
operator ++,operator--generation conditionsUnitGenerateOptions.ValueArithmeticOperatorUnitGenerateOptions.ArithmeticOperator, withUnitArithmeticOperators.Number(default) or.Increment/.DecrementUnitOfarguments[UnitOf(..., ArithmeticOperator = ...]toStringFormatis changed to a named parameter from 3rd argument.