================================================================================
basic/float
================================================================================

amends "../snippetTest.pkl"

import "pkl:math"

facts {
  ["pow"] {
    2.0 ** 3.0 ** 4.0 == 2.0 ** (3.0 ** 4.0)
    1.0 + 2.0 ** 3.0 == 1.0 + (2.0 ** 3.0)
    2.0 * 2.0 ** 3.0 == 2.0 * (2.0 ** 3.0)
    2.0 ** 3.0 + 1.0 == (2.0 ** 3.0) + 1.0
    2.0 ** 3.0 * 2.0 == (2.0 ** 3.0) * 2.0
  }

  ["equality"] {
    1.2 == 1.2
    1.0 == 1
    1 == 1.0
    !(1.2 == 1.3)
    !(1.2 == 1)
  }

  ["inequality"] {
    1.2 != 1.3
    1.2 != 1
    !(1.0 != 1)
    !(1.2 != 1.2)
    !(1 != 1.0)
  }

  ["greater than"] {
    1.3 > 1.2
    !(1.2 > 1.2)
    !(1.2 > 1.3)
  }

  ["less than"] {
    1.2 < 1.3
    !(1.2 < 1.2)
    !(1.3 < 1.2)
  }

  ["greater than or equal"] {
    1.2 >= 1.2
    1.3 >= 1.2
    !(1.2 >= 1.3)
  }

  ["less than or equal"] {
    1.2 <= 1.2
    1.2 <= 1.3
    !(1.3 <= 1.2)
  }

  ["underscores"] {
    123_456_789.123_456_789 == 123456789.123456789
    1____.1____ == 1.1
    1____1.1____1 == 11.11

    123.4_56e7 == 123.456e7
    123.4_56e-7 == 123.456e-7

    123.456e1_0 == 123.456e10
    1_23.456e-1_0 == 123.456e-10
  }
}

examples {
  ["literal"] {
    123456789.123456789
    123.456e7
    123.456e-7

    -123456789.123456789
    -123.456e7
    -123.456e-7

    4.9E-324
    1.7976931348623157E308

    123_456_789.123_456_789
    1____.1____
    1____1.1____1

    123.4_56e7
    123.4_56e-7

    123.456e1_0
    1_23.456e-1_0
  }

  ["addition"] {
    1.1 + 2.2
    1 + 2.2
  }

  ["subtraction"] {
    2.2 - 3.3
    2.2 - 3
  }

  ["multiplication"] {
    3.3 * 4.4
    3 * 4.4
  }

  ["division"] {
    4.4 / 5.5
    4.4 / 5
  }

  ["integer division"] {
    5 ~/ 3
    5.0 ~/ 3
    5 ~/ 3.0
    5.0 ~/ 3.0
    5.1 ~/ 3.1
  }

  ["remainder"] {
    5.5 % 6.5
    5 % 6.5
  }

  ["negation"] {
    // pkl, js, dart, and kotlin use #1; their grammar has no negative numeric literals
    // ruby and scala use #2 (scala switched from #1 around 2.8)
    //
    // 1.
    // local x = 1.2
    // -1.2.abs == -(1.2.abs)
    // -x.abs == -(x.abs)
    //
    // 2.
    // local x = 1.2
    // -1.2.abs == (-1.2).abs
    // -x.abs == -(x.abs)
    //
    // #1 is more intuitive for negative numeric literals, but less consistent

    local x = 1.2

    -1.2.abs
    -x.abs
  }

  ["power"] {
    2.3 ** 4.0
    2.3 ** 0.0
    2.3 ** -4.0

    0.0 ** 0.0
    1.0 ** 0.0
    -1.0 ** 0.0

    0.0 ** 1.0
    1.0 ** 1.0
    -1.0 ** 1.0

    0.0 ** -1.0
    1.0 ** -1.0
    -1.0 ** -1.0

    0.0 ** 42.0
    1.0 ** 42.0
    -1.0 ** 42.0

    0.0 ** -42.0
    1.0 ** -42.0
    -1.0 ** -42.0

    0.0 ** math.maxFiniteFloat
    1.0 ** math.maxFiniteFloat
    -1.0 ** math.maxFiniteFloat

    0.0 ** math.minFiniteFloat
    1.0 ** math.minFiniteFloat
    -1.0 ** math.minFiniteFloat

    2.0 ** math.maxInt8
    2.0 ** math.maxInt16
    2.0 ** math.maxInt32
    2.0 ** math.maxInt
    2.0 ** math.maxFiniteFloat
    -2.0 ** math.maxInt8
    -2.0 ** math.maxInt16
    -2.0 ** math.maxInt32
    -2.0 ** math.maxInt
    -2.0 ** math.maxFiniteFloat

    math.maxFiniteFloat ** 0.0
    math.maxFiniteFloat ** 1.0
    math.maxFiniteFloat ** 2.0
  }
}

--------------------------------------------------------------------------------

(module
  (moduleHeader
    (extendsOrAmendsClause
      (stringConstant)))
  (importClause
    (stringConstant))
  (classProperty
    (identifier)
    (objectBody
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (binaryExprRightAssoc
                  (floatLiteral)
                  (floatLiteral)))
              (binaryExprRightAssoc
                (floatLiteral)
                (parenthesizedExpr
                  (binaryExprRightAssoc
                    (floatLiteral)
                    (floatLiteral))))))
          (objectElement
            (binaryExpr
              (binaryExpr
                (floatLiteral)
                (binaryExprRightAssoc
                  (floatLiteral)
                  (floatLiteral)))
              (binaryExpr
                (floatLiteral)
                (parenthesizedExpr
                  (binaryExprRightAssoc
                    (floatLiteral)
                    (floatLiteral))))))
          (objectElement
            (binaryExpr
              (binaryExpr
                (floatLiteral)
                (binaryExprRightAssoc
                  (floatLiteral)
                  (floatLiteral)))
              (binaryExpr
                (floatLiteral)
                (parenthesizedExpr
                  (binaryExprRightAssoc
                    (floatLiteral)
                    (floatLiteral))))))
          (objectElement
            (binaryExpr
              (binaryExpr
                (binaryExprRightAssoc
                  (floatLiteral)
                  (floatLiteral))
                (floatLiteral))
              (binaryExpr
                (parenthesizedExpr
                  (binaryExprRightAssoc
                    (floatLiteral)
                    (floatLiteral)))
                (floatLiteral))))
          (objectElement
            (binaryExpr
              (binaryExpr
                (binaryExprRightAssoc
                  (floatLiteral)
                  (floatLiteral))
                (floatLiteral))
              (binaryExpr
                (parenthesizedExpr
                  (binaryExprRightAssoc
                    (floatLiteral)
                    (floatLiteral)))
                (floatLiteral))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (intLiteral)))
          (objectElement
            (binaryExpr
              (intLiteral)
              (floatLiteral)))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (floatLiteral)
                  (floatLiteral)))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (floatLiteral)
                  (intLiteral)))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (intLiteral)))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (floatLiteral)
                  (intLiteral)))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (floatLiteral)
                  (floatLiteral)))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (intLiteral)
                  (floatLiteral)))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (floatLiteral)
                  (floatLiteral)))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (floatLiteral)
                  (floatLiteral)))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (floatLiteral)
                  (floatLiteral)))))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (floatLiteral)
                  (floatLiteral)))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (floatLiteral)
                  (floatLiteral)))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (unaryExpr
              (parenthesizedExpr
                (binaryExpr
                  (floatLiteral)
                  (floatLiteral)))))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))))))
  (classProperty
    (identifier)
    (objectBody
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (floatLiteral))
          (objectElement
            (floatLiteral))
          (objectElement
            (binaryExpr
              (binaryExpr
                (binaryExpr
                  (floatLiteral)
                  (floatLiteral))
                (floatLiteral))
              (floatLiteral)))
          (objectElement
            (floatLiteral))
          (objectElement
            (floatLiteral))
          (objectElement
            (floatLiteral))
          (objectElement
            (floatLiteral))
          (objectElement
            (floatLiteral))
          (objectElement
            (floatLiteral))
          (objectElement
            (floatLiteral))
          (objectElement
            (floatLiteral))
          (objectElement
            (floatLiteral))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (intLiteral)
              (floatLiteral)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (intLiteral)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (intLiteral)
              (floatLiteral)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (intLiteral)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (intLiteral)
              (intLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (intLiteral)))
          (objectElement
            (binaryExpr
              (intLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExpr
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (intLiteral)
              (floatLiteral)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (lineComment)
          (objectProperty
            (modifier)
            (identifier)
            (propertyCallExpr
              (binaryExpr
                (propertyCallExpr
                  (binaryExpr
                    (floatLiteral)
                    (floatLiteral))
                  (identifier))
                (variableExpr
                  (identifier)))
              (identifier)))))
      (objectEntry
        (slStringLiteral)
        (objectBody
          (objectElement
            (binaryExprRightAssoc
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExprRightAssoc
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExprRightAssoc
              (floatLiteral)
              (unaryExpr
                (floatLiteral))))
          (objectElement
            (binaryExprRightAssoc
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (floatLiteral))
              (binaryExprRightAssoc
                (floatLiteral)
                (floatLiteral))))
          (objectElement
            (binaryExprRightAssoc
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (floatLiteral))
              (binaryExprRightAssoc
                (floatLiteral)
                (floatLiteral))))
          (objectElement
            (binaryExprRightAssoc
              (floatLiteral)
              (unaryExpr
                (floatLiteral))))
          (objectElement
            (binaryExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (unaryExpr
                  (floatLiteral)))
              (binaryExprRightAssoc
                (floatLiteral)
                (unaryExpr
                  (floatLiteral)))))
          (objectElement
            (binaryExprRightAssoc
              (floatLiteral)
              (floatLiteral)))
          (objectElement
            (binaryExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (floatLiteral))
              (binaryExprRightAssoc
                (floatLiteral)
                (floatLiteral))))
          (objectElement
            (binaryExprRightAssoc
              (floatLiteral)
              (unaryExpr
                (floatLiteral))))
          (objectElement
            (binaryExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (unaryExpr
                  (floatLiteral)))
              (binaryExprRightAssoc
                (floatLiteral)
                (unaryExpr
                  (floatLiteral)))))
          (objectElement
            (propertyCallExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (variableExpr
                  (identifier)))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (binaryExpr
                (propertyCallExpr
                  (binaryExprRightAssoc
                    (floatLiteral)
                    (variableExpr
                      (identifier)))
                  (identifier))
                (binaryExprRightAssoc
                  (floatLiteral)
                  (variableExpr
                    (identifier))))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (variableExpr
                  (identifier)))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (binaryExpr
                (propertyCallExpr
                  (binaryExprRightAssoc
                    (floatLiteral)
                    (variableExpr
                      (identifier)))
                  (identifier))
                (binaryExprRightAssoc
                  (floatLiteral)
                  (variableExpr
                    (identifier))))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (variableExpr
                  (identifier)))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (variableExpr
                  (identifier)))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (variableExpr
                  (identifier)))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (binaryExprRightAssoc
                (floatLiteral)
                (variableExpr
                  (identifier)))
              (identifier)))
          (objectElement
            (propertyCallExpr
              (binaryExpr
                (propertyCallExpr
                  (binaryExpr
                    (propertyCallExpr
                      (binaryExpr
                        (propertyCallExpr
                          (binaryExpr
                            (propertyCallExpr
                              (binaryExpr
                                (propertyCallExpr
                                  (binaryExprRightAssoc
                                    (floatLiteral)
                                    (variableExpr
                                      (identifier)))
                                  (identifier))
                                (binaryExprRightAssoc
                                  (floatLiteral)
                                  (variableExpr
                                    (identifier))))
                              (identifier))
                            (binaryExprRightAssoc
                              (floatLiteral)
                              (variableExpr
                                (identifier))))
                          (identifier))
                        (binaryExprRightAssoc
                          (floatLiteral)
                          (variableExpr
                            (identifier))))
                      (identifier))
                    (binaryExprRightAssoc
                      (floatLiteral)
                      (variableExpr
                        (identifier))))
                  (identifier))
                (binaryExprRightAssoc
                  (floatLiteral)
                  (variableExpr
                    (identifier))))
              (identifier)))
          (objectElement
            (binaryExprRightAssoc
              (propertyCallExpr
                (variableExpr
                  (identifier))
                (identifier))
              (floatLiteral)))
          (objectElement
            (binaryExprRightAssoc
              (propertyCallExpr
                (variableExpr
                  (identifier))
                (identifier))
              (floatLiteral)))
          (objectElement
            (binaryExprRightAssoc
              (propertyCallExpr
                (variableExpr
                  (identifier))
                (identifier))
              (floatLiteral))))))))
