How to perform Mathematical Operations using different ways in Kotlin

In my last semester, I studied about parser in compiler design. But that was all theoretical.I wanted to do something practical. So I decided to make Arithmetic Parser Library with all trigonometric, logarithmic functions which could also be used by others to evaluate expression. And kotlin language is very easy to write and idiomatic.

In Java, operators are tied to specific Java types. For example, String and numeric types in Java can use the + operator for concatenation and addition, respectively. No other Java type can reuse this operator for its own benefit. Kotlin, on the contrary, provides a set of conventions to support limited Operator Overloading.

Assignment Operator is used to assigning values to variables. The value after evaluation on the left-hand side is assigned to the variable of the right-hand side. Besides the basic = assignment operator, Kotlin provides a wide range of assignment Operators which are mentioned below.

Now for this we will create evaluate(expression:String) function.Now, what will be inside the evaluate function?Well, The Core idea is to search in the expression for an operator. Then split the expression in two parts. Part 1 (Left from operator) and Part 2 (Right from operator). Then recusively evaluate the value of Part 1 and Part 2 with evaluate() and then finally evaluate the answers of part1 and part2 with the found operator.

See Also  Chess game development in android studio

Increment and Decrement operators can be used before and after a variable but both have different meanings. If increment or decrement operator is used before the variable name then the value of that variable is changed first before any other operation on the variable. If the increment or decrement operator is used after a variable name then its value is changed after the other operation on that variable.

In the above example, the value of b is first incremented by 1 and then assigned to variable ‘increment’ whereas the value of c is first assigned to variable dec and then decreases by 1.

The following article, provide an outline of the most commonly used operators in Kotlin. Operators are basically special symbols that are used to perform specific operations on the operands. For an example (-) operator is used to perform a subtraction between two operands.

See Also  Android Spinner with Search using XML Tutorial

In my last semester, I studied about parser in compiler design. But that was all theoretical.I wanted to do something practical. So I decided to make Arithmetic Parser Library with all trigonometric, logarithmic functions which could also be used by others to evaluate expression. And kotlin language is very easy to write and idiomatic.

In Java, operators are tied to specific Java types. For example, String and numeric types in Java can use the + operator for concatenation and addition, respectively. No other Java type can reuse this operator for its own benefit. Kotlin, on the contrary, provides a set of conventions to support limited Operator Overloading.

Assignment Operator is used to assigning values to variables. The value after evaluation on the left-hand side is assigned to the variable of the right-hand side. Besides the basic = assignment operator, Kotlin provides a wide range of assignment Operators which are mentioned below.

Now for this we will create evaluate(expression:String) function.Now, what will be inside the evaluate function?Well, The Core idea is to search in the expression for an operator. Then split the expression in two parts. Part 1 (Left from operator) and Part 2 (Right from operator). Then recusively evaluate the value of Part 1 and Part 2 with evaluate() and then finally evaluate the answers of part1 and part2 with the found operator.

See Also  How to create Android WebView App from Scratch

Increment and Decrement operators can be used before and after a variable but both have different meanings. If increment or decrement operator is used before the variable name then the value of that variable is changed first before any other operation on the variable. If the increment or decrement operator is used after a variable name then its value is changed after the other operation on that variable.

In the above example, the value of b is first incremented by 1 and then assigned to variable ‘increment’ whereas the value of c is first assigned to variable dec and then decreases by 1.

The following article, provide an outline of the most commonly used operators in Kotlin. Operators are basically special symbols that are used to perform specific operations on the operands. For an example (-) operator is used to perform a subtraction between two operands.

See Also  Primary & Secondary Constructors & init Block in Kotlin
d93f3bce1660660e5de55f10d6df6f1a?s=96&d=mm&r=g
SyncSaShttps://syncsas.com
SyncSaS Technologies is specialized in creating and designing customized software. We have our own team that will be in charge of developing your softwares.

More from author

Related posts

Advertismentspot_img

Latest posts

How to increase YouTube Subscribers 2 Organic Strategy

How to increase YouTube Subscribers Being a YouTube personalities everyone wants the number of channel subscribers should multiply very quickly. Making YouTube video and uploading...

5 Ways to Increase Your YouTube Views

Increase Your YouTube Views Try going back and editing it to make it even better, and work on new videos. A helpful tip is to...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!