This Fortran module implements several procedures for handling rational numbers. Currently implemented are:
rationalnumber_t
Name | Type | Description |
---|---|---|
ratNumInit | function | Initializes a new rationalnumber_t variable with given numerator and denominator values. |
ratNumInitFromReal | function | Initializes a new rationalnumber_t variable from a real value. |
ratNumToStr | function | Converts a rationalnumber_t variable into its string representation. |
ratNumEqualize | subroutine | Makes the denominators of two rationalnumber_t variables equal. |
ratNumSimplify | function | Simplifies a rationalnumber_t variable, reducing its numerator and denominator without affecting its value. E.g. 5/10 --> 1/2. |
ratNumAdd | function | Adds two rationalnumber_t variables together. |
ratNumSubstract | function | Substracts two rationalnumber_t variables. |
ratNumSetNumerator | subroutine | Sets the numerator value. |
ratNumGetNumerator | function | Returns the numerator value. |
ratNumSetDenominator | subroutine | Sets the denominator value. Has no effect if the new value is 0. |
ratNumGetDenominator | function | Returns the denominator value. |
ratNumToReal | function | Converts a rationalnumber_t variable into its standard Fortran real value representation. |
- No integer overflow detection/handling. Behaviour is undefined with numerator or denominator values exceeding the limits of the standard Fortran
integer
type. - Currently there are no procedures for other basic operations than addition.
The only dependency is the math module. This module will be included automatically when compiled by FPM.
- Install FPM (Fortran Package Manager) and copy it into your $PATH as
fpm
. - Clone the git repository.
- Execute the command
fpm build
inside the base directory of the repository. This will also fetch and build the required math library. - This library includes a simple test program. It can be easily executed with
fpm test
.
This library was compiled with GFortran and packaged with FPM.