pieterderycke / Jace

Jace.NET is a calculation engine for the .NET platform.
MIT License
436 stars 94 forks source link

sqrt(): return positive and negative values #39

Open helluvamatt opened 5 years ago

helluvamatt commented 5 years ago

According to Wikipedia:

In mathematics, a square root of a number a is a number y such that y^2 = a; in other words, a number y whose square (the result of multiplying the number by itself, or y ⋅ y) is a. For example, 4 and −4 are square roots of 16 because 42 = (−4)2 = 16.

To facilitate this, an Operation would be need to handle processing and returning two doubles. Each operation would have to decide if it will operate on the double and possibly filter out double.NaN.

I see this as a major overhaul and a major breaking change, and would require a bump in the major version if following semver.

Once that overhaul is complete, it would be trivial to return new Tuple<double, double>(Math.Sqrt(x), -Math.Sqrt(x)) for the Sqrt function operation. ~Alternatively, a new internal model could be passed around that includes the double result as well as a flag that indicates the next operation should be performed on both the result and the negation of the result.~ Edit: This would not work as the next operation may alter the negation result differently and that information would need to be communicated to further operations and eventually the caller.

Thoughts?

pieterderycke commented 5 years ago

I am not really convinced of the added value of returning back a tuple. It will complixify the use of Jace without bringing sufficient added value.