Skip to content

core — examples

← all topics · 500 examples · page 5 of 10 · raw source ↓

Runs `go` → 15

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Algo_SumOfDigits   topic: core   status: verified
// verified behavior: Test.go(...) == 15

namespace Test
func digitSum(n: int) -> int {
    var x = n
    var sum = 0
    while x > 0 {
        sum += x % 10
        x /= 10
    }
    return sum
}
func go() -> int { return digitSum(12345) }

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Bool_AndOrNot_Keyword   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool { return (true and false) or not false }

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Bool_AndOrNot_Symbolic   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool { return (true && false) || !false }

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Bool_DeMorgan   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func check(a: bool, b: bool) -> bool {
    return !(a && b) == (!a || !b)
}
func go() -> bool {
    return check(true, false) && check(true, true) && check(false, false)
}

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Bool_FromComparisonChainStored   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool {
    let n = 5
    let inRange = n >= 1 && n <= 10
    return inRange
}

Runs `go` → false

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Bool_NestedParentheses   topic: core   status: verified
// verified behavior: Test.go(...) == false

namespace Test
func go() -> bool {
    return (true && (false || (true && false)))
}

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Bool_XorViaNotEqual   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool {
    return (true != false) && !(true != true)
}

Runs `echo` → (byte)200

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Byte_Identity   topic: core   status: verified
// verified behavior: Test.echo(...) == (byte)200

namespace Test
func echo(b: byte) -> byte { return b }

Runs `go` → (byte)255

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Byte_MaxValueConstant   topic: core   status: verified
// verified behavior: Test.go(...) == (byte)255

namespace Test
func go() -> byte { return byte.MaxValue }

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Char_Equality   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool {
    let c = 'x'
    return c == 'x'
}

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Char_EscapeSequences   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool {
    let tab = '\t'
    let nl = '\n'
    return tab != nl
}

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Char_FromStringIndex   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool {
    let s = "hello"
    return s[1] == 'e'
}

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Char_IsDigit_BclInterop   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool {
    return char.IsDigit('7')
}

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Char_IsLetter   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool { return char.IsLetter('q') }

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Char_IsWhiteSpace   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool { return char.IsWhiteSpace(' ') }

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Char_Ordering   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool { return 'a' < 'b' && 'z' > 'a' }

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Char_ToUpper   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool { return char.ToUpper('a') == 'A' }

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Comparison_Operators   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool {
    return 3 < 4 && 4 <= 4 && 5 > 4 && 5 >= 5 && 3 == 3 && 3 != 4
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_Add   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> double { return 3.0 + 1.5 }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_CompoundAssign   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> double {
    var x = 4.0
    x *= 2.5
    return x
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_Division   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> double { return 5.0 / 2.0 }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_MathAbs   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> double { return Math.Abs(0.0 - 3.5) }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_MathCeiling   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> double { return Math.Ceiling(3.1) }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_MathFloor   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> double { return Math.Floor(3.9) }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_MathPow   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> double { return Math.Pow(2.0, 3.0) }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_MathSqrt   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> double { return Math.Sqrt(16.0) }

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_NegativeAndComparison   topic: core   status: verified
// verified behavior: Test.go(...) == true

namespace Test
func go() -> bool {
    let a = -2.5
    let b = 1.5
    return a < b && b > a
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_ScientificNotation   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> double { return 1.0e10 }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_SubtractionPrecision   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> double { return 2.0 - 1.5 }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Double_UsingStaticMath   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
using static "System.Math"
func go() -> double { return Sqrt(25.0) }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Float_Add   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func add(a: float, b: float) -> float { return a + b }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Float_Multiply   topic: core   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func mul(a: float, b: float) -> float { return a * b }

Runs `go` → 6

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_AccumulateAcrossCalls   topic: core   status: verified
// verified behavior: Test.go(...) == 6

namespace Test
func bump(c: *int) {
    c += 1
}
func go() -> int {
    var count = 3
    bump(&count)
    bump(&count)
    bump(&count)
    return count
}

Runs `add` → 7

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_Add   topic: core   status: verified
// verified behavior: Test.add(...) == 7

namespace Test
func add(a: int, b: int) -> int { return a + b }

Runs `scale` → 45

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_ChainedCompoundOnParam   topic: core   status: verified
// verified behavior: Test.scale(...) == 45

namespace Test
func scale(start: int, factor: int) -> int {
    var n = start
    n *= factor
    n += factor
    return n
}

Runs `go` → 13

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_CompoundAssignAll   topic: core   status: verified
// verified behavior: Test.go(...) == 13

namespace Test
func go() -> int {
    var n = 10
    n += 5
    n -= 2
    n *= 2
    n /= 2
    return n
}

Runs `go` → 5

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_DoubleNegation   topic: core   status: verified
// verified behavior: Test.go(...) == 5

namespace Test
func go() -> int {
    let x = 5
    return 0 - (0 - x)
}

Runs `go` → 4

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_LeftAssociativeDivision   topic: core   status: verified
// verified behavior: Test.go(...) == 4

namespace Test
func go() -> int { return 100 / 5 / 5 }

Runs `go` → -6

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_LeftAssociativeSubtraction   topic: core   status: verified
// verified behavior: Test.go(...) == -6

namespace Test
func go() -> int { return 1 - 2 - 5 }

Runs `go` → 7

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_MathMax   topic: core   status: verified
// verified behavior: Test.go(...) == 7

namespace Test
func go() -> int { return Math.Max(3, 7) }

Runs `go` → 3

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_MathMin   topic: core   status: verified
// verified behavior: Test.go(...) == 3

namespace Test
func go() -> int { return Math.Min(3, 7) }

Runs `go` → int.MaxValue

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_MaxValueConstant   topic: core   status: verified
// verified behavior: Test.go(...) == int.MaxValue

namespace Test
func go() -> int { return int.MaxValue }

Runs `go` → int.MinValue

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_MinValueConstant   topic: core   status: verified
// verified behavior: Test.go(...) == int.MinValue

namespace Test
func go() -> int { return int.MinValue }

Runs `go` → 17

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_MixedArithmeticExpression   topic: core   status: verified
// verified behavior: Test.go(...) == 17

namespace Test
func go() -> int { return 2 * 3 + 4 * 2 + 3 }

Runs `go` → 1

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_Modulo   topic: core   status: verified
// verified behavior: Test.go(...) == 1

namespace Test
func go() -> int { return 7 % 3 }

Runs `go` → 0

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_ModuloZeroRemainder   topic: core   status: verified
// verified behavior: Test.go(...) == 0

namespace Test
func go() -> int { return 12 % 4 }

Runs `go` → 15

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_MutateThroughPointer   topic: core   status: verified
// verified behavior: Test.go(...) == 15

namespace Test
func addTo(target: *int, amount: int) {
    target += amount
}
func go() -> int {
    var n = 10
    addTo(&n, 5)
    return n
}

Runs `go` → -5

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_NegativeLiteral   topic: core   status: verified
// verified behavior: Test.go(...) == -5

namespace Test
func go() -> int { return -5 }

Runs `go` → -1

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_NegativeModulo_FollowsClr   topic: core   status: verified
// verified behavior: Test.go(...) == -1

namespace Test
func go() -> int { return -7 % 3 }

Runs `go` → int.MinValue

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Numerics.cs::Int_OverflowWrapsUnchecked   topic: core   status: verified
// verified behavior: Test.go(...) == int.MinValue

namespace Test
func go() -> int { return int.MaxValue + 1 }