Decimal compare
decimal-compare · version 1.0.0 · Numbers & math · free, no key needed
Compare two decimal strings exactly after canonicalization.
Use when you need to: decimal compare · compare decimals · cmp decimal strings.
Supported
- decimal compare
- compare decimals
- cmp decimal strings
Not supported
- ieee754
- epsilon
- locale
Behavior
- Input decimal strings: /^-?(0|[1-9][0-9]*)(\.[0-9]+)?$/.
- Reject leading zeros, plus signs, spaces, exponents, bare ".", trailing ".", empty, and NaN/Infinity tokens.
- At most 40 digits excluding sign and decimal point. At most 18 fractional digits on input.
- Canonicalize: strip trailing fractional zeros; drop the decimal point if the fraction vanishes; normalize -0 and -0.0 to "0".
- Exact decimal arithmetic with BigInt scaled integers. No IEEE-754 intermediates. Never return JSON BigInt.
- result is -1, 0, or 1 after canonical numeric compare. 1.0 equals 1.
Input
a(string, required): min length 1; max length 44b(string, required): min length 1; max length 44
Output
result(one of -1, 0, 1, required)
Limits
- max digits: 40
- max scale: 18
Example
Request input:
{
"a": "1.0",
"b": "1"
}
Response:
{
"result": {
"result": 0
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "decimal-compare",
"version": "1.0.0",
"input": {
"a": "1.0",
"b": "1"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/decimal-compare/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"a":"1.0","b":"1"}'
The machine-readable contract is at /v1/tools/decimal-compare/versions/1.0.0.
CLI
node cli.mjs run decimal-compare 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Integer compare: Compare two canonical signed base-10 integer strings using BigInt.
- Decimal add: Exact decimal addition of canonicalizable decimal strings.
- Decimal subtract: Exact decimal subtraction a minus b of canonicalizable decimal strings.
- Array integer cumulative sum: Replace an array of canonical integer strings with equal-length prefix sums.
- Array integer median: Select lower and upper middle canonical integers; emit median only for odd length.
- Array integer mode: Return the most frequent canonical integers, listing every mode in first-seen order.