A 3D Dynamic Geometry Software

Calques 3D C++



Fraction.h File Reference


Detailed Description

Interface of the CFraction class - Code for handling fraction strings.

Author:
Dean Wyant dwyant@mindspring.com
This class is used like a double. Do anything you would do with a double, plus assign strings to it. When you need to get a string representation, use one of the String calls. My favorite is ForceToStockString which returns a string for the closest valid stock transaction denominator up to MaxDen (default 256). This is great for applications that need to show stock prices in fractions without resorting to a table lookup or showing unusual prices in decimal.

C calls and plain calls for ASCIIZ support are provided

A description of the Fraction Algorithm is also given.


Classes

class  CFraction
 CFraction - Code for handling fraction strings. More...

Defines

#define FRACTION_MAX_PRECISION   10.0e-15
 Significant digits.

Functions

double Fracatof (const char *pszNum)
 Convert string that may include a fraction to floating point (double).
char * Fracftoa (double f, char *pszBuffer, double AllowedError=FRACTION_MAX_PRECISION)
 Convert double to a string that includes the whole part, space, and the fraction (numerator/denominator).
char * Fracftoa (double f, char *pszBuffer, int MaxDen)
 Convert double to a string that includes the whole part, space, and the fraction (numerator/denominator).
char * DoubleToStockString (double f, char *pszBuffer, int MaxDen=256)
 Returns 6.4f unless denominator is less than or equal to MaxDen and in 2,4,8,16,32,64,128,256.
char * ForceDoubleToStockString (double f, char *pszBuffer, int MaxDen=256)
 Returns closest fraction string with a denominator less than or equal to MaxDen and in 2,4,8,16,32,64,128,256.
double FracParts (double f, __int64 &Whole, __int64 &Num, __int64 &Den, double AllowedError=FRACTION_MAX_PRECISION)
 Convert a double to its fractional parts.
double FracParts (double f, __int64 &Whole, __int64 &Num, __int64 &Den, int MaxDen)
 Convert a double to its fractional parts.
double FracPartsStock (double f, __int64 &Whole, __int64 &Num, __int64 &Den, int MaxDen)
 Convert a double to its fractional parts.