/// <summary> /// The kelvin to gas conversion. /// </summary> /// <param name="firstTemp"> The temperature to convert. </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> Temp too low or too high for gas mark! </exception> /// <returns> /// The converted temperature. /// </returns> public static double KelvinToGas(double firstTemp) { var celsiusTemp = KelvinToCelsius(firstTemp); var gasTemp = CelsiusConverter.CelsiusToGas(celsiusTemp); return(gasTemp); }
/// <summary> /// Converts the float input to the correct float value. /// </summary> /// <typeparam name="TInput"> The temperature type to be converted to. </typeparam> /// <param name="input"> The value to be converted. </param> /// <exception cref="ArgumentException"> The TInput type is not a valid type for this method. </exception> /// <returns> /// The result of the conversion. /// </returns> public static float To <TInput>(this FloatBase input) where TInput : TemperatureBase { return(typeof(TInput).Name switch { nameof(Celsius) when input is CelsiusFloat castInput => FloatParser(CelsiusConverter.CelsiusToCelsius(castInput.Temperature)), nameof(Celsius) when input is FahrenheitFloat castInput => FloatParser(FahrenheitConverter.FahrenheitToCelsius(castInput.Temperature)), nameof(Celsius) when input is KelvinFloat castInput => (float)Math.Round(FloatParser(KelvinConverter.KelvinToCelsius(castInput.Temperature)), 2), nameof(Celsius) when input is GasFloat castInput => FloatParser(GasConverter.GasToCelsius(castInput.Temperature)), nameof(Celsius) when input is RankineFloat castInput => (float)Math.Round(FloatParser(RankineConverter.RankineToCelsius(castInput.Temperature)), 2), nameof(Fahrenheit) when input is CelsiusFloat castInput => FloatParser(CelsiusConverter.CelsiusToFahrenheit(castInput.Temperature)), nameof(Fahrenheit) when input is FahrenheitFloat castInput => FloatParser(FahrenheitConverter.FahrenheitToFahrenheit(castInput.Temperature)), nameof(Fahrenheit) when input is KelvinFloat castInput => (float)Math.Round(FloatParser(KelvinConverter.KelvinToFahrenheit(castInput.Temperature)), 2), nameof(Fahrenheit) when input is GasFloat castInput => FloatParser(GasConverter.GasToFahrenheit(castInput.Temperature)), nameof(Fahrenheit) when input is RankineFloat castInput => FloatParser(RankineConverter.RankineToFahrenheit(castInput.Temperature)), nameof(Kelvin) when input is CelsiusFloat castInput => FloatParser(CelsiusConverter.CelsiusToKelvin(castInput.Temperature)), nameof(Kelvin) when input is FahrenheitFloat castInput => FloatParser(FahrenheitConverter.FahrenheitToKelvin(castInput.Temperature)), nameof(Kelvin) when input is KelvinFloat castInput => FloatParser(KelvinConverter.KelvinToKelvin(castInput.Temperature)), nameof(Kelvin) when input is GasFloat castInput => FloatParser(GasConverter.GasToKelvin(castInput.Temperature)), nameof(Kelvin) when input is RankineFloat castInput => FloatParser(RankineConverter.RankineToKelvin(castInput.Temperature)), nameof(Gas) when input is CelsiusFloat castInput => FloatParser(CelsiusConverter.CelsiusToGas(castInput.Temperature)), nameof(Gas) when input is FahrenheitFloat castInput => FloatParser(FahrenheitConverter.FahrenheitToGas(castInput.Temperature)), nameof(Gas) when input is KelvinFloat castInput => FloatParser(KelvinConverter.KelvinToGas(castInput.Temperature)), nameof(Gas) when input is GasFloat castInput => FloatParser(GasConverter.GasToGas(castInput.Temperature)), nameof(Gas) when input is RankineFloat castInput => FloatParser(RankineConverter.RankineToGas(castInput.Temperature)), nameof(Rankine) when input is CelsiusFloat castInput => FloatParser(CelsiusConverter.CelsiusToRankine(castInput.Temperature)), nameof(Rankine) when input is FahrenheitFloat castInput => FloatParser(FahrenheitConverter.FahrenheitToRankine(castInput.Temperature)), nameof(Rankine) when input is KelvinFloat castInput => FloatParser(KelvinConverter.KelvinToRankine(castInput.Temperature)), nameof(Rankine) when input is GasFloat castInput => FloatParser(GasConverter.GasToRankine(castInput.Temperature)), nameof(Rankine) when input is RankineFloat castInput => FloatParser(RankineConverter.RankineToRankine(castInput.Temperature)), _ => throw new ArgumentException($"Invalid type: {typeof(TInput).Name}") });
/// <summary> /// The kelvin to fahrenheit conversion. /// </summary> /// <param name="firstTemp"> The temperature to convert. </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> If calculated value is beyond the limits of the type. </exception> /// <returns> /// The converted temperature. /// </returns> public static double KelvinToFahrenheit(double firstTemp) { var celsiusTemp = KelvinToCelsius(firstTemp); var fahrenheitTemp = CelsiusConverter.CelsiusToFahrenheit(celsiusTemp); return(fahrenheitTemp); }
/// <summary> /// The rankine to gas conversion. /// </summary> /// <param name="input"> The temperature to convert. </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> If calculated value is beyond the limits of the type. </exception> /// <returns> /// The converted temperature. /// </returns> public static double RankineToGas(double input) { var celsiusTemp = RankineToCelsius(input); var gasTemp = CelsiusConverter.CelsiusToGas(celsiusTemp); return(gasTemp); }
/// <summary> /// Converts the Double input to the correct double value. /// </summary> /// <typeparam name="TInput"> The temperature type to be converted to. </typeparam> /// <param name="input"> The value to be converted. </param> /// <exception cref="ArgumentException"> The TInput type is not a valid type for this method. </exception> /// <returns> /// The result of the conversion. /// </returns> public static double To <TInput>(this DoubleBase input) where TInput : TemperatureBase { return(typeof(TInput).Name switch { nameof(Celsius) when input is CelsiusDouble castInput => CelsiusConverter.CelsiusToCelsius(castInput.Temperature), nameof(Celsius) when input is FahrenheitDouble castInput => FahrenheitConverter.FahrenheitToCelsius(castInput.Temperature), nameof(Celsius) when input is KelvinDouble castInput => KelvinConverter.KelvinToCelsius(castInput.Temperature), nameof(Celsius) when input is GasDouble castInput => GasConverter.GasToCelsius(castInput.Temperature), nameof(Celsius) when input is RankineDouble castInput => RankineConverter.RankineToCelsius(castInput.Temperature), nameof(Fahrenheit) when input is CelsiusDouble castInput => CelsiusConverter.CelsiusToFahrenheit(castInput.Temperature), nameof(Fahrenheit) when input is FahrenheitDouble castInput => FahrenheitConverter.FahrenheitToFahrenheit(castInput.Temperature), nameof(Fahrenheit) when input is KelvinDouble castInput => KelvinConverter.KelvinToFahrenheit(castInput.Temperature), nameof(Fahrenheit) when input is GasDouble castInput => GasConverter.GasToFahrenheit(castInput.Temperature), nameof(Fahrenheit) when input is RankineDouble castInput => RankineConverter.RankineToFahrenheit(castInput.Temperature), nameof(Kelvin) when input is CelsiusDouble castInput => CelsiusConverter.CelsiusToKelvin(castInput.Temperature), nameof(Kelvin) when input is FahrenheitDouble castInput => FahrenheitConverter.FahrenheitToKelvin(castInput.Temperature), nameof(Kelvin) when input is KelvinDouble castInput => KelvinConverter.KelvinToKelvin(castInput.Temperature), nameof(Kelvin) when input is GasDouble castInput => GasConverter.GasToKelvin(castInput.Temperature), nameof(Kelvin) when input is RankineDouble castInput => RankineConverter.RankineToKelvin(castInput.Temperature), nameof(Gas) when input is CelsiusDouble castInput => CelsiusConverter.CelsiusToGas(castInput.Temperature), nameof(Gas) when input is FahrenheitDouble castInput => FahrenheitConverter.FahrenheitToGas(castInput.Temperature), nameof(Gas) when input is KelvinDouble castInput => KelvinConverter.KelvinToGas(castInput.Temperature), nameof(Gas) when input is GasDouble castInput => GasConverter.GasToGas(castInput.Temperature), nameof(Gas) when input is RankineDouble castInput => RankineConverter.RankineToGas(castInput.Temperature), nameof(Rankine) when input is CelsiusDouble castInput => CelsiusConverter.CelsiusToRankine(castInput.Temperature), nameof(Rankine) when input is FahrenheitDouble castInput => FahrenheitConverter.FahrenheitToRankine(castInput.Temperature), nameof(Rankine) when input is KelvinDouble castInput => KelvinConverter.KelvinToRankine(castInput.Temperature), nameof(Rankine) when input is GasDouble castInput => GasConverter.GasToRankine(castInput.Temperature), nameof(Rankine) when input is RankineDouble castInput => RankineConverter.RankineToRankine(castInput.Temperature), _ => throw new ArgumentException($"Invalid type: {typeof(TInput).Name}") });
public void KelvinToCelsuis(decimal input, decimal expectedResult) { var cc = new CelsiusConverter(); var temp = new Temperature(input, Unit.Kelvin); var result = cc.FromKelvin(temp); Assert.Equal(expectedResult, Math.Round(result.Value, 2)); }
/// <summary> /// Converts the Celsius <paramref name="input"/> to FahrenheitConverter /// </summary> /// <param name="input"> The value to be converted. </param> /// <exception cref="T:System.ArgumentOutOfRangeException">If calculated value is beyond the limits of the type.</exception> /// <returns> /// The FahrenheitConverter <see langword="float"/> result. /// </returns> public static float ToFahrenheit(this CelsiusFloat input) { return(FloatParser(CelsiusConverter.CelsiusToFahrenheit(input.Temperature))); }
/// <summary> /// Converts the Celsius <paramref name="input"/> to RankineConverter /// </summary> /// <param name="input"> The value to be converted. </param> /// <exception cref="T:System.ArgumentOutOfRangeException">If calculated value is beyond the limits of the type.</exception> /// <returns> /// The RankineConverter <see langword="float"/> result. /// </returns> public static float ToRankine(this CelsiusFloat input) { return(FloatParser(CelsiusConverter.CelsiusToRankine(input.Temperature))); }
/// <summary> /// Converts the Celsius <paramref name="input"/> to FahrenheitConverter /// </summary> /// <param name="input"> The value to be converted. </param> /// <exception cref="T:System.ArgumentOutOfRangeException">If calculated value is beyond the limits of the type.</exception> /// <returns> /// The FahrenheitConverter <see langword="int"/> result. /// </returns> public static int ToFahrenheit(this CelsiusInt input) { return(IntParser(CelsiusConverter.CelsiusToFahrenheit(input.Temperature))); }
/// <summary> /// Converts the Celsius <paramref name="input"/> to RankineConverter /// </summary> /// <param name="input"> The value to be converted. </param> /// <exception cref="T:System.ArgumentOutOfRangeException">If calculated value is beyond the limits of the type.</exception> /// <returns> /// The RankineConverter <see langword="int"/> result. /// </returns> public static int ToRankine(this CelsiusInt input) { return(IntParser(CelsiusConverter.CelsiusToRankine(input.Temperature))); }
/// <summary> /// Converts the Celsius <paramref name="input"/> to FahrenheitConverter /// </summary> /// <param name="input"> The value to be converted. </param> /// <exception cref="T:System.ArgumentOutOfRangeException">If calculated value is beyond the limits of the type.</exception> /// <returns> /// The FahrenheitConverter <see langword="double"/> result. /// </returns> public static double ToFahrenheit(this CelsiusDouble input) { return(CelsiusConverter.CelsiusToFahrenheit(input.Temperature)); }
/// <summary> /// Converts the Celsius <paramref name="input"/> to Ranking /// </summary> /// <param name="input"> The value to be converted. </param> /// <returns> /// The RankineConverter <see langword="double"/> result. /// </returns> public static double ToRankine(this CelsiusDouble input) { return(CelsiusConverter.CelsiusToRankine(input.Temperature)); }