Closed notKamui closed 7 months ago
The multication symbol should still be * even if you do this
@realeatham I vehemently disagree.
If the button is ×, then pressing it should show × and not *.
Keval was made to be this customizable, there is absolutely no valid reason to have a discrepancy between what's written and what is evaluated. This will also greatly simplify the code.
I'd like to do that yeah ! How do I create for example a "+" ? (maybe I shouldnt ask that lol) I don't plan to add any more operators yes
@realeatham
Changing * to x is simpler since i wont have to use a .replace() method
I think its with this :
Keval.create { // builder instance includeDefault() // this function includes the built-in resources
binaryOperator { // this function adds a binary operator ; you can call it several times
symbol = ';'
precedence = 3
isLeftAssociative = true
implementation = { a, b -> a.pow(2) + b.pow(2) }
}
unaryOperator { // this function adds a unary operator ; you can call it several times
symbol = '#'
isPrefix = false
implementation = { arg -> (1..arg.toInt()).fold(0.0) { acc, i -> acc + i } }
}
function { // this function adds a function ; you can call it several times
name = "max"
arity = 2
implementation = { args -> max(args[0], args[1]) }
}
constant { // this function adds a constant ; you can call it several times
name = "PHI"
value = 1.618
}
}
But there are some Math things I dont understand 🥲
@sosauce
what do you not understand ?
I'll make a PR for you btw
@sosauce I did the thing: #55
Thank you so much ahhhh alos, the opt in are becaise my AS tweaks and forgets sometimes 😅
Hey, Keval's creator here again. I suggest you use Keval's full ability to be customizable to only implement the operators you need instead of loading the full default resources.
This will also allow you to make the
×
symbol to the multiplication instead of*
, which goes more in line with how you buttons work.Moreover, this will allow you to add other operators that users might want. For example, I saw some people had issues with the modulo operator, thinking it is the percentage unary postfix operator. I don't agree that such an operator should be implement, I find it dumb to have a button to do basically
/100
. However, this could allow you to implement an unambiguousmod(n, c)
function for example, and others as need, to make you calculator a scientific calculator in landscape mode.Even if you don't plan on adding the features mentioned in the previous paragraph, you should still instanciate a custom Keval instance with only what you need.
I could make a PR for you if you don't have time.