Kotlin Manual Testing

I am contributing the Kotlin Compiler Fuzzer(Kai) in Google summer of code.

i want test kotlin language features and build in method.
my aim is, i am one of the part of kotlin programming language development.
if any Developer given me a guidance.

i am Non-IT employee (9:00 to 5:00)Job. i am not complete the Degree, After completed my work, i start learning coding, Because i love it.
This is My GitHub Link :

BigDecimal working Good.

fun main()

{

//BigDecimal
val a = “+0.1”.toBigDecimal()
val b = “-0.3”.toBigDecimal()
println(a+b) // -0.2

}

i was changed something.

fun main()

{

val sum = “0.1 + 0.2”.toBigDecimal()
println(sum) // compile time No problem. Run time error message’s came.

/*
Exception in thread “main” java.lang.NumberFormatException: Character is neither a decimal digit number, decimal point, nor “e” notation exponential mark.
at java.base/java.math.BigDecimal.(BigDecimal.java:608)
at java.base/java.math.BigDecimal.(BigDecimal.java:497)
at java.base/java.math.BigDecimal.(BigDecimal.java:903)
*/

}

My question is :
i am doing this write or wrong ?

Thank You for all Developers :slight_smile:

The problem is

val sum = "0.1 + 0.2".toBigDecimal()

The toBigDecimal method converts a String containing some kind of number to a BigDecimal. It is not a parser able to do calculations (something like eval in JavaScript), it expects just a number in a certain format, that’s it, no functions, no operations, not even alternative decimal seperators.

As far as I know, there is nothing built directly in the language which could do such evaluations (except maybe some super hacky abuse of the compiler at runtime, which is probably not a good idea). You would either need to use some library, or write a parser yourself (which is a great learning opportunity, in my opinion, but maybe a little bit too complicated for you right now)

A quick search brought up GitHub - Keelar/ExprK: A simple mathematical expression evaluator for Kotlin and Java, written in Kotlin. · GitHub as a library, but I didn’t try it out.