-
Notifications
You must be signed in to change notification settings - Fork 383
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
Creating generic version of structs (WIP) #714
base: master
Are you sure you want to change the base?
Conversation
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bad bot |
I have a few questions as to what the expectations are for the generic structs:
|
First, wow, nice brain dump :-)
I don't think so? I can't think of any good reason why we should.
Yes, I guess.
Did I understand right that you want to this naming?
How about If we introduce separate nugets for the different numeric types, then another option is to introduce You pretty much lost me at points 7-8 and onwards 😆 This all sounds very complicated on the first read-through. It's been too long since I last had my brain on this subject, so I keep forgetting all the pitfalls and pros/cons of solutions and ideas in the previous discussions. For one, this PR absolutely need a summary in its description that explains why this is a good idea, what it solves, who cares, what the downsides are - and it needs to be short and concise 😄 If you intend to follow up further on this, I'd start with this summary. |
I knew I should have started with (9) :)
I don't much care for floats anyway- do you see a reason (other than ~completeness) why we should have it at all?
Yes, that's what I initially thought as well- but I think the decision on this depends on the casting scheme we select- sticking with the strict casting rules will protect us from having a In summary- my intuition tells me that in order to accomplish this task- we first have to ensure the operator generation- since there is no base class where contributors can add operators that work on all domains- we would have to either force them to create them for each domain (not acceptable) or figure out a way to generate them from whatever is given in the JSON (I haven't yet touched on this in #709 but the rest of the operator generation ideas are there). |
Lol, I checked the Earth & Solar masses- turns out they are pretty big- ~6e24 & ~2e30 respectively- so I guess |
I am not sure why we would have any more packages. I would just expect consumers to define a quantity as say |
Maybe at the end of porting the whole thing to generics, the current genericless classes should inherit from the SomeUnit one. And in theory every users of the types fall back on their feet. |
You can't derive from a class of the same name. Would probably have to change the name of the generic type somehow to keep the current naming. |
Maybe I misunderstand but you can technically derive from the same name- as long as the namespace is different. Again I apologize for the 10 point comment- although the points still appear valid (even after a later re-read)- the most important question in my view is found my last comment about the range & the astronomical units. Could you comment on it please? @tmilnthorp @angularsen |
Sorry I haven't had a chance to look through them yet. In those cases you should receive an OverflowException |
Yeah, I guess there is no way around it- other than going for some BigDecimal implementation (there were talks about Rationals before- so given the compiled lambdas flexibility - this might not be an outlandish idea). |
Yea exactly, the generic type is pretty powerful. There's a |
I did a double double implementation. Maybe it could be added to UnitsNet. |
Hi guys, I have a hard time finding the time to help move this forward, but one thing I'm still missing from this discussion is; although it's fun to contemplate what we can do, we also need to consider what we should do. Why are we adding this? For my simple uses of this library, I have neither missed I can see that for astronomical units and very big/small units, a greater range and precision may be required. I'm speculating that this is may be a minority use case though. I'm happy to support it, but only if it doesn't complicate the simple, mainstream use cases or the learning curve and discoverability. Either by adding new complicated concepts to understand, multiple types or generics to choose from or maybe placing types in different namespaces. I'm simply trying to keep it simple and make sure we only create something that people actually will use and benefit from. One thing that would help immensely for me at least, is to have a summary of
Cheers 🍻 |
You are right. Before going forward with such an extensive change we should make sure it has benefits accross the board. For me it just make sense to have that possibility. But there should be hard facts attached to it. |
# Conflicts: # CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs # CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs # CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs # UnitsNet.Tests/CompiledLambdasTests.cs # UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs # UnitsNet.Tests/CustomCode/LengthTests.FeetInches.cs # UnitsNet.Tests/CustomCode/MassConcentrationTests.cs # UnitsNet.Tests/CustomCode/PressureTests.cs # UnitsNet.Tests/GeneratedCode/AmountOfSubstanceTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/AmplitudeRatioTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ApparentEnergyTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ApparentPowerTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/AreaDensityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/AreaMomentOfInertiaTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/BrakeSpecificFuelConsumptionTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/CapacitanceTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/CoefficientOfThermalExpansionTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/DurationTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/DynamicViscosityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricAdmittanceTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricChargeDensityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricChargeTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricConductanceTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricConductivityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricCurrentDensityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricCurrentGradientTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricCurrentTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricFieldTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricInductanceTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricPotentialAcTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricPotentialDcTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricPotentialTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricResistanceTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ElectricSurfaceChargeDensityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/EnergyTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/EntropyTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ForcePerLengthTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ForceTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/FrequencyTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/FuelEfficiencyTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/HeatTransferCoefficientTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs # UnitsNet.Tests/GeneratedCode/IlluminanceTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/KinematicViscosityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/LapseRateTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/LevelTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/LinearDensityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/LuminosityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/LuminousFluxTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/LuminousIntensityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/MagneticFieldTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/MagneticFluxTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/MagnetizationTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/MassFluxTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/MolarEnergyTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/MolarEntropyTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/MolarityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/PermeabilityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/PermittivityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/PowerRatioTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/PowerTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/PressureChangeRateTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/RatioChangeRateTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/RatioTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ReactiveEnergyTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ReactivePowerTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/RotationalAccelerationTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/RotationalStiffnessPerLengthTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/RotationalStiffnessTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/SolidAngleTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/SpecificEnergyTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/SpecificVolumeTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TemperatureDeltaTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TemperatureTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ThermalConductivityTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/ThermalResistanceTestsBase.g.cs # UnitsNet.Tests/GeneratedCode/VitaminATestsBase.g.cs # UnitsNet.Tests/GeneratedCode/VolumePerLengthTestsBase.g.cs # UnitsNet.Tests/QuantityInfoTest.cs # UnitsNet.Tests/QuantityTests.Ctor.cs # UnitsNet.Tests/QuantityTests.ToString.cs # UnitsNet.Tests/QuantityTests.cs # UnitsNet/CompiledLambdas.cs # UnitsNet/CustomCode/Quantities/ForcePerLength.extra.cs # UnitsNet/CustomCode/Quantities/Length.extra.cs # UnitsNet/CustomCode/Quantity.cs # UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs # UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs # UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs # UnitsNet/GeneratedCode/Quantities/Angle.g.cs # UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs # UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs # UnitsNet/GeneratedCode/Quantities/Area.g.cs # UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs # UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs # UnitsNet/GeneratedCode/Quantities/BitRate.g.cs # UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs # UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs # UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs # UnitsNet/GeneratedCode/Quantities/Density.g.cs # UnitsNet/GeneratedCode/Quantities/Duration.g.cs # UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs # UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs # UnitsNet/GeneratedCode/Quantities/Energy.g.cs # UnitsNet/GeneratedCode/Quantities/Entropy.g.cs # UnitsNet/GeneratedCode/Quantities/Force.g.cs # UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs # UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs # UnitsNet/GeneratedCode/Quantities/Frequency.g.cs # UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs # UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs # UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs # UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs # UnitsNet/GeneratedCode/Quantities/Information.g.cs # UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs # UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs # UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs # UnitsNet/GeneratedCode/Quantities/LapseRate.g.cs # UnitsNet/GeneratedCode/Quantities/Length.g.cs # UnitsNet/GeneratedCode/Quantities/Level.g.cs # UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs # UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs # UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs # UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs # UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs # UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs # UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs # UnitsNet/GeneratedCode/Quantities/Mass.g.cs # UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs # UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs # UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs # UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs # UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs # UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs # UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs # UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs # UnitsNet/GeneratedCode/Quantities/Molarity.g.cs # UnitsNet/GeneratedCode/Quantities/Permeability.g.cs # UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs # UnitsNet/GeneratedCode/Quantities/Power.g.cs # UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs # UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs # UnitsNet/GeneratedCode/Quantities/Pressure.g.cs # UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs # UnitsNet/GeneratedCode/Quantities/Ratio.g.cs # UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs # UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs # UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs # UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs # UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs # UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs # UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs # UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs # UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs # UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs # UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs # UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs # UnitsNet/GeneratedCode/Quantities/Speed.g.cs # UnitsNet/GeneratedCode/Quantities/Temperature.g.cs # UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs # UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs # UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs # UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs # UnitsNet/GeneratedCode/Quantities/Torque.g.cs # UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs # UnitsNet/GeneratedCode/Quantities/Volume.g.cs # UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs # UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs # UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs # UnitsNet/GeneratedCode/Quantity.g.cs # UnitsNet/GeneratedCode/UnitConverter.g.cs # UnitsNet/QuantityTypeConverter.cs # UnitsNet/UnitConverter.cs
- Add `struct` generic constraint to T - Add GenericNumberHelper for MinValue, MaxValue - Add T to Parse - Add T to Equals The biggest blocker is the conversion functions, how to take dynamic code from JSON and make it work with generics. UnitsNet.Angle.GetValueAs UnitsNet.Angle.GetValueInBaseUnit
@tmilnthorp I took a look, merged in latest
The biggest blocker I'm seeing right now are the conversion functions.
Non-trivial example from #883
|
Now that Net 7 preview 5 is 9ut generic math are a lot more advanced in their development. There exist an IFloatingPoint interface that constraint numbers to floating point types and this includes decimal. It could be used to make sure no integer types are used. I think using generics as the core of UnitsNet makes a lot of sense. |
Initial pass. Still a WIP. Any help appreciated!
Needs some additional changes (NaN handling, etc.).