DEV Community

Discussion on: A pure functional Primality Test in Scala

Collapse
 
markclewis profile image
Mark Lewis

I would suggest that you not use math.pow to square things. Just do i*i instead of math.pow(i, 2). I expect that you will find it is much faster to run in addition to being shorter to type. As a general rule, using math.pow is inefficient for any small integer power. In this case, it is particularly bad because i is an integer and math.pow is working with doubles and the conversion from Int to Double also has a cost.

Collapse
 
guildenstern70 profile image
Alessio Saltarin

Done, thank you!