# Rational compare

`rational-compare` · version 1.0.0 · Numbers & math · free, no key needed

Compare two rational numbers given as numerator/denominator integer strings by exact value.

**Use when you need to: rational compare · compare two rational numbers · compare fractions as rationals.**

## Supported

- rational compare
- compare two rational numbers
- compare fractions as rationals
- order two rationals

## Not supported

- decimal compare
- float comparison
- mixed numbers
- IEEE-754 arithmetic

## Behavior

- Each operand is an object with canonical integer-string numerator and denominator fields.
- The denominator must be a positive canonical integer; zero and negative denominators are rejected.
- Inputs may use -0, which is canonicalized to 0; every other integer must match 0 or -?[1-9][0-9]*.
- Comparison is by exact value: a.numerator * b.denominator versus b.numerator * a.denominator.
- Input operands need not be in lowest terms; comparison ignores representation, only value.
- result is -1 if a<b, 0 if equal, and 1 if a>b. result is a JSON integer, not BigInt.
- Each numerator and denominator may have at most 1000 digits excluding sign.

## Input

- `a` (object, required)
- `b` (object, required)

## Output

- `result` (one of -1, 0, 1, required)

## Limits

- max digits: 1000

## Example

Request input:

```json
{
  "a": {
    "numerator": "1",
    "denominator": "3"
  },
  "b": {
    "numerator": "1",
    "denominator": "2"
  }
}
```

Response:

```json
{
  "result": {
    "result": -1
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "rational-compare",
  "version": "1.0.0",
  "input": {
    "a": {
      "numerator": "1",
      "denominator": "3"
    },
    "b": {
      "numerator": "1",
      "denominator": "2"
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/rational-compare/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"a":{"numerator":"1","denominator":"3"},"b":{"numerator":"1","denominator":"2"}}'
```

The machine-readable contract is at [/v1/tools/rational-compare/versions/1.0.0](/v1/tools/rational-compare/versions/1.0.0).

### CLI

```sh
node cli.mjs run rational-compare 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Rational add](/tools/rational-add): Add two rational numbers given as numerator/denominator integer strings and return the reduced sum.
- [Rational multiply](/tools/rational-multiply): Multiply two rational numbers given as numerator/denominator integer strings and return the reduced product.
- [Rational subtract](/tools/rational-subtract): Subtract one rational number from another, given as numerator/denominator integer strings, and return the reduced difference.
- [Array rational sum](/tools/array-rational-sum): Sum an array of canonical rationals and return the reduced total.
- [Array rational mean](/tools/array-rational-mean): Return the reduced arithmetic mean of an array of canonical rationals.
- [Array rational min max](/tools/array-rational-min-max): Return the reduced numeric minimum and maximum of an array of canonical rationals.
