Conversation
|
d2:log and d2:pow to program rule grammard2:log and d2:exponent to program rule grammar
| /** | ||
| * Tests the `pow` function | ||
| * | ||
| * @author Jan Bernitt / Tony Valle |
There was a problem hiding this comment.
I was not the author of this file ;)
There was a problem hiding this comment.
Should I swap the order of the names or remove your name entirely? (I kept it because the file is basically a literal translation of the log test)
| fun testExponent() { | ||
| assertEquals(1.0, evaluate("d2:exponent(49, 0)")) | ||
| assertEquals(7.0, evaluate("d2:exponent(49, 0.5)")) | ||
| assertEquals(49.0, evaluate("d2:exponent(49, 1)")) |
There was a problem hiding this comment.
How about at least one case where we use the function with a exponent > 1?
| NamedFunction.isNull -> functions.isNull(evalToMixed(fn.child(0))) | ||
| NamedFunction.least -> functions.least(evalToNumbers(fn.children())) | ||
| NamedFunction.log -> if (fn.size() == 1) functions.log(evalToNumber(fn.child(0))) | ||
| NamedFunction.log, NamedFunction.d2_log -> if (fn.size() == 1) functions.log(evalToNumber(fn.child(0))) |
There was a problem hiding this comment.
Is there a reason to add d2:log when log already exists?
There was a problem hiding this comment.
The reason is that all other program rule functions use the d2:-prefix.
- Edit author - Correction of the test title - Adds a test case for exponent > 1 and exponent < 0




Things to look at:
logfunction inCalculator.kt, and I just copy-pasted the implementation. A more clever solution might exist.powfor "raising a number to a power", and I think C++ uses the same name. Personally I associate this operation more with the nameexp. The advocates forpowprobably argue thatexpis another function (e^x). Regardless, I tend to look upexprather thanpowif I want to "exponentiate" something, and chances are this is true for other people as well.Update:
logandd2_log.powtoexponent(as suggested in the roadmap).