public override CalcQuantity Calculate_Here(IList <CalcQuantity> args, UOMSet uomSet) { if (args.Count != 2) { return(new BadCalcQuantity(Name + " must have 2 arguments")); } if ((args[0].CalcStatus != CalcStatus.Good) || (args[1].CalcStatus != CalcStatus.Good)) { return(new BadCalcQuantity("Missing or bad arguments")); } if (!AnonUOM.EqualOrNull(args[0].AnonUOM, args[1].AnonUOM)) { return(new BadCalcQuantity("Inconsistent Units")); } try { CalcQuantity result = CalcQuantity.NewMathResult( value: (args[0].Value + args[1].Value), anonUOM: args[0].AnonUOM); return(result); } catch (Exception) { return(new BadCalcQuantity("Calculation error")); } }
public override CalcQuantity Calculate_Here(IList <CalcQuantity> args, UOMSet uomSet) { if (args.Count != 1) { return(new BadCalcQuantity(Name + " must have 1 argument")); } if ((args[0].CalcStatus != CalcStatus.Good)) { return(new BadCalcQuantity("Missing or bad arguments")); } if (!Dimensions.Equals(args[0]?.AnonUOM?.Dimensions, ArgDimensions)) { return(new BadCalcQuantity("Bad argument dimensions")); } try { AnonUOM resAnonUOM = new AnonUOM(ResultDimensions, uomSet); CalcQuantity result = CalcQuantity.NewMathResult( value: CalcValue(args[0].Value), anonUOM: resAnonUOM); return(result); } catch (Exception) { return(new BadCalcQuantity("Calculation error")); } }
public override CalcQuantity Calculate_Here(IList <CalcQuantity> args, UOMSet uomSet) { if (args.Count != 2) { return(new BadCalcQuantity(Name + " must have 2 arguments")); } if ((args[0].CalcStatus != CalcStatus.Good) || (args[1].CalcStatus != CalcStatus.Good)) { return(new BadCalcQuantity("Missing or bad arguments")); } if (!Dimensions.IsDimenionless(args[1]?.AnonUOM?.Dimensions)) { return(new BadCalcQuantity("Exponent must be dimensionless")); } try { Dimensions resDim = Dimensions.MultiplyDimensions(args[0]?.AnonUOM?.Dimensions, args[1].Value); AnonUOM resAnonUOM = new AnonUOM(resDim, uomSet); CalcQuantity result = CalcQuantity.NewMathResult( value: Math.Pow(args[0].Value, args[1].Value), anonUOM: resAnonUOM); return(result); } catch (Exception) { return(new BadCalcQuantity("Calculation error")); } }
public override CalcQuantity Calculate_Here(IList <CalcQuantity> args, UOMSet uomSet) { if (args.Count != 1) { return(new BadCalcQuantity(Name + " must have 1 argument")); } if (args[0].CalcStatus != CalcStatus.Good) { return(new BadCalcQuantity("Missing or bad arguments")); } try { CalcQuantity result = CalcQuantity.NewMathResult( value: (-1 * args[0].Value), anonUOM: args[0].AnonUOM); return(result); } catch (Exception) { return(new BadCalcQuantity("Calculation error")); } }