serso / android-calculatorpp

Android Calculator
421 stars 201 forks source link

Function names evaluate as constants #211

Open hackerb9 opened 1 year ago

hackerb9 commented 1 year ago

Some function names are buggy. If the user defines a function EIGhtieth, it will evaluate to iEIGeh^2t^2.

This seems to happen when a capital E is used in the name.

Screenshot_20230125-104207

derei commented 1 month ago

@hackerb9 ... I would expect more insight from someone whose username contains "hacker" 🤭.

Whilst I cannot give you a 100% confirmed answer for this particular situation, based on general programming practices and conventions, variables which start with capital letter are in general evaluated as constants.

... so, perhaps use lowercase to name your functions? 😁.

Peace!

gustav-langer commented 1 day ago

Note that this only happens if the function name starts with an E, i.e. you can name a function eIGHTIETH or eightiEth or whatever and it will still work fine.

I haven't really looked into this app's code yet but I can imagine this happening when the parser enters a special mode for detecting expressions like 1E10, and then fails to leave it correctly when it's part of a name.

This could probably be fixed but I personally have no idea how.