RATIONAL(1)

NAME
rational - test program for the Rational number class

SYNOPSIS
rational [options] [arguments]

DESCRIPTION
Rational is a C++ class implementing rational numbers of limited size with overflow detection. Both numerator and denominator are of type 'int'.

Rational allows you to perform exact calculations and verify at any time if overflow has occurred. Rational does not throw exceptions.

In case of domain error or overflow, denominator is set to 0 and numerator is set to >0, <0, or 0, meaning +INF, -INF, and NAN respectively. This error condition can be tested with the function 'error', and can only be cleared by assigning a new value to the Rational.

While in error state, arithmetic operators become no ops and relational operators return false, except '!=', which returns true. This is done to preserve the error condition which triggered the error, and because the error value is considered to be out of domain and therefore is different from any valid value, but not necessarily larger or smaller.

The function 'parse' can be used to obtain values exactly representable by small fractions like '0.1', '1/3', or '355/113' from the command line.

The function 'to_decimal' prints values in decimal point form (123.456), while the function 'to_fraction' prints values in fraction form (123/456). Both functions print '+INF', '-INF', or 'NAN' to signal an error condition.

Values are kept normalized (gcd(numerator,denominator) == 1, and the denominator is positive). Range extends from INT_MAX to -INT_MAX. Maximum resolution is 1 / INT_MAX.

To use the class Rational in your own programs simply copy the files 'rational.h' and 'rational.cc' in your source tree. See the file 'main.cc' for an example of use.

OPTIONS

-h, --help
    display this help and exit

-V, --version
    output version information and exit

-g, --golden-ratio
    calculate approximations of (1 + sqrt(5)) / 2

-p, --pi
    calculate approximations of pi

-q, --quiet
    quiet operation

-s, --sqrt=<n>
    calculate approximations of sqrt(n)

-t, --test=<level>
    run tests at given level (1-9)

-v, --verbose
    verbose operation

The option '-s, --sqrt' accepts a rational argument.

REPORTING BUGS
Report bugs to arg-parser-bug@nongnu.org
Rational home page: http://www.nongnu.org/arg-parser/rational.html

COPYRIGHT
Copyright © 2022 Antonio Diaz Diaz. License 2-clause BSD.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.