Math

object Math

General Math

Math type in Scalqa is an alias to scala.math.Numeric. Generally "Math" is a better name for what Numeric stands for.

Math object contains few shortcuts to java.lang.Math static methods.

Source
__.scala
class java.lang.Object
trait scala.Matchable
class Any

Member

opaque type BigDecimal

Big BigDecimal

BigDecimal is an opaque value holding java.math.BigDecimal

BigDecimal is used for really large floating point calculations

 // Calculate number Pi using Nilakantha series

 ~~(2.0.Big)
   .unfold(_.last + 4)
   .takeFirst(1000) // the more - the better
   .map(v => (4.0.Big / (v * (v + 1) * (v + 2)) - 4.0.Big / ((v + 2) * (v + 3) * (v + 4))))
   .fold(3.0.Big)(_ + _)
   .tp

 // Prints: 3.1415926535585900763679167025419016466613791096007613231066955478
Source
BigDecimal.scala
opaque type BigInteger

Big Integer

BigInteger is an opaque value holding java.math.BigInteger

BigInteger is used for really large integer calculations

val max: BigInteger = ~~(58).repeat(35).foldAs(1.Big)(_ * _)

"Largest Bitcoin address= " + max + ", digits=" + max.toString.length tp()

val TenB = 10.Big * 1000 * 1000 * 1000
val YearSecs = 60.Big * 60 * 24 * 365

"Suppose, there is 10 billion computers in the world capable counting 10 billion numbers per second each" tp()
"  Together they will count " + (TenB * TenB) + " in a second" tp()
"  Together they will count " + (TenB * TenB * YearSecs) + " in a year" tp()
"  Together they will count " + (TenB * TenB * YearSecs * TenB) + " in 10 billions years - the 'Age of Universe'" tp()
"It is required "   +   (max / ((TenB * TenB * YearSecs * TenB))) + " 'Ages of Universe'" tp()
"for all todays computers together to just simply count all Bitcoin adresses" tp()

// Output ****************************************************************************************************************
Largest Bitcoin address= 52478302028992644968172978478148648556151605660894866578604032, digits=62
Suppose, there is 10 billion computers in the world capable counting 10 billion numbers per second each
 Together they will count 100000000000000000000 in a second
 Together they will count 3153600000000000000000000000 in a year
 Together they will count 31536000000000000000000000000000000000 in 10 billions years - the 'Age of Universe'
It is required 1664076041000527808478341 'Ages of Universe'
for all todays computers together to just simply count all Bitcoin adresses
Source
BigInteger.scala
opaque type Format
trait Ordering[A] extends scala.Ordering[A]

General Ordering

Note. Scalqa classes do not use this trait directly, but rather its parent scala.math.Ordering

All methods defined here are also available on scala.math.Ordering as extensions.

This trait is usefull for creating new orderings.

Source
__.scala
trait Ordering[A] extends scala.Ordering[A]

General Ordering

Note. Scalqa classes do not use this trait directly, but rather its parent scala.math.Ordering

All methods defined here are also available on scala.math.Ordering as extensions.

This trait is usefull for creating new orderings.

Source
__.scala
abstract class Rounding
Source
__.scala
abstract class Rounding
Source
__.scala

Def

inline def ceil(inline v: Double): Double
Source
__.scala
inline def floor(inline v: Double): Double
Source
__.scala
inline def log10(inline v: Double): Double
Source
__.scala
inline def pow(inline a: Double, inline b: Double): Double
Source
__.scala