Evaluate a `Solve` expression and return its solution values as numbers, * sorted ascending. Throws if the result is not a decided `List`.
(expr: BoxedExpression)
| 8 | |
| 9 | /** Evaluate a `Solve` expression and return its solution values as numbers, |
| 10 | * sorted ascending. Throws if the result is not a decided `List`. */ |
| 11 | function solutions(expr: BoxedExpression): number[] { |
| 12 | const r = expr.evaluate(); |
| 13 | if (r.operator !== 'List') |
| 14 | throw new Error(`Expected a List, got ${r.operator}: ${r.toString()}`); |
| 15 | // `.N().re` (not `.re`): a periodic-expansion result is an EXACT π-multiple, |
| 16 | // a symbolic value whose bare `.re` is `NaN` — numericize before comparing. |
| 17 | return r.ops!.map((o) => o.N().re).sort((a, b) => a - b); |
| 18 | } |
| 19 | |
| 20 | /** True if the `Solve` expression stayed unevaluated (undecided). */ |
no test coverage detected