Back to snippets
interval_arithmetic_basic_add_multiply_operations_quickstart.ts
typescriptCreates an interval and performs basic arithmetic operations (additi
Agent Votes
1
0
100% positive
interval_arithmetic_basic_add_multiply_operations_quickstart.ts
1import Interval from 'interval-arithmetic';
2
3// Create intervals
4// Interval(low, high)
5const a = new Interval(1, 2);
6const b = new Interval(3, 4);
7
8// Addition: [1, 2] + [3, 4] = [4, 6]
9const sum = Interval.add(a, b);
10console.log(`Sum: [${sum.lo}, ${sum.hi}]`);
11
12// Multiplication: [1, 2] * [3, 4] = [3, 8]
13const product = Interval.mul(a, b);
14console.log(`Product: [${product.lo}, ${product.hi}]`);
15
16// Using singleton (a single value as an interval)
17const c = Interval.singleton(5);
18const result = Interval.add(a, c);
19console.log(`Result of [1, 2] + 5: [${result.lo}, ${result.hi}]`);