|
Dynamic Fraction Library 1.0.0
Reference-counted arbitrary precision rational number library (MIT OR Unlicense)
|
 
A single-header C library implementing arbitrary precision rational numbers (fractions) with reference counting, built on top of dynamic_int.h for seamless arbitrary precision arithmetic.
dynamic_fraction.hFull API documentation is available at: https://[your-repo].github.io/dynamic_fraction.h/
Customize the library by defining these macros before including:
df_from_ints(), df_from_int() - Create from integersdf_from_di() - Create from dynamic integersdf_from_double() - Create from floating point (with precision limit)df_from_string() - Create from string representation ("3/4", "5", "-2/3")df_zero(), df_one(), df_neg_one() - Create common constantsdf_retain() - Increment reference countdf_release() - Decrement reference count and free if neededdf_add(), df_sub(), df_mul(), df_div() - Basic arithmeticdf_negate(), df_abs(), df_reciprocal() - Unary operationsdf_pow() - Exponentiation with integer exponentsdf_cmp(), df_eq(), df_ne(), df_lt(), df_le(), df_gt(), df_ge() - Comparisonsdf_min(), df_max() - Min/max operationsdf_floor(), df_ceil(), df_trunc() - Rounding operationsdf_round() - Round to nearest integer (banker's rounding for ties)df_to_double(), df_to_int64() - Convert to native typesdf_to_string() - Convert to string representationdf_is_zero(), df_is_one(), df_is_integer() - Type predicatesdf_is_positive(), df_is_negative() - Sign testingdf_fits_int32(), df_fits_int64(), df_fits_double() - Range checkingdf_numerator(), df_denominator() - Extract componentsdf_whole_part(), df_fractional_part() - Split into integer and fractional partsdf_sign() - Get sign (-1, 0, 1)df_hash() - Hash function for use in hash tablesThe library uses reference counting for automatic memory management:
devDeps/)This project is dual-licensed under:
Choose whichever license works best for your project.
This library supports:
Contributions are welcome! Please feel free to submit issues and pull requests.