Skip to content

art-rasa/rational_number

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rational_number

Introduction

This Fortran module implements several procedures for handling rational numbers. Currently implemented are:

Data types

  • rationalnumber_t

Procedures

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.

Known bugs/limitations

  1. No integer overflow detection/handling. Behaviour is undefined with numerator or denominator values exceeding the limits of the standard Fortran integer type.
  2. Currently there are no procedures for other basic operations than addition.

Dependencies

The only dependency is the math module. This module will be included automatically when compiled by FPM.

Building the library:

  • 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.

About

Fortran module for handling rational numbers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published