/// <inheritdoc/> public IHasValue Create(string value) { if (string.IsNullOrEmpty(value)) { throw new ArgumentNullException(nameof(value)); } if (decimal.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out decimal number)) { return(_numberFactory.CreateNumber(number)); } if (_knownBinaryFunctions.TryGetValue(value, out Func <IHasValue> binaryFunctionFactory)) { return(binaryFunctionFactory()); } if (_knownUnaryFunctions.TryGetValue(value, out Func <IHasValue> unaryFunctionFactory)) { return(unaryFunctionFactory()); } throw new NotSupportedException( _resourceStore.GetExceptionMessage("UnknownCalculationObject", value)); }
/// <inheritdoc /> protected override IHasValue Calculate(IHasValue firstArg, IHasValue secondArg) { decimal firstValue = firstArg.GetValue(); decimal secondValue = secondArg.GetValue(); return(_numberFactory.CreateNumber(firstValue + secondValue)); }
/// <inheritdoc /> protected override IHasValue Calculate(IHasValue firstArg, IHasValue secondArg) { decimal firstValue = firstArg.GetValue(); decimal secondValue = secondArg.GetValue(); if (secondValue == 0) { throw new ArgumentOutOfRangeException(nameof(secondArg), ResourceStore.GetExceptionMessage("DenominatorIsZero")); } return(_numberFactory.CreateNumber(firstValue / secondValue)); }
/// <inheritdoc /> protected override IHasValue Calculate(IHasValue argument) { decimal value = (decimal)Math.Log2((double)argument.GetValue()); return(_numberFactory.CreateNumber(value)); }