This Fortran module implements several procedures for handling rational numbers. Currently implemented are:
- rationalnumber_t
| Name | Type | Description | 
|---|---|---|
| ratNumInit | function | Initializes a new rationalnumber_tvariable with given numerator and denominator values. | 
| ratNumInitFromReal | function | Initializes a new rationalnumber_tvariable from arealvalue. | 
| ratNumToStr | function | Converts a rationalnumber_tvariable into its string representation. | 
| ratNumEqualize | subroutine | Makes the denominators of two rationalnumber_tvariables equal. | 
| ratNumSimplify | function | Simplifies a rationalnumber_tvariable, reducing its numerator and denominator without affecting its value. E.g. 5/10 --> 1/2. | 
| ratNumAdd | function | Adds two rationalnumber_tvariables together. | 
| ratNumSubstract | function | Substracts two rationalnumber_tvariables. | 
| 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_tvariable into its standard Fortranrealvalue representation. | 
- No integer overflow detection/handling. Behaviour is undefined with numerator or denominator values exceeding the limits of the standard Fortran integertype.
- 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 buildinside 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.