Skip to content

PsychoCod3r/libdfloat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction:

libdfloat is a floating point library for C that represents decimal numbers precisely with no rounding errors. It provides four types for representing decimal floating point numbers, as well as functions for reading/writing these numbers to/from strings and performing arithmetic operations with the numbers. These arithmetic operations are carried out in roughly the same way arithmetic is done on floating point numbers in the IEEE-754 standard, except the numbers have a decimal base.


Why did I write this library?

Reading and writing decimal numbers from/to a CSV database or other text file can result in problems when numbers are represented in a binary format by the C program. Rounding errors can occur, resulting in values getting truncated during conversion between the decimal and binary bases. Also, the textual representation of floating point numbers via a function like fprintf() can often have trailing zeros and other problems that make a number difficult to write back to the file in the same format it was read from. The goal of libdfloat is to preserve the representation of decimal numbers so that they are written back to the text file in the same format they were in when read.


Who is this library for?

libdfloat is intended for programmers who work with text-based flat-file databases in their programs, but it can theoretically be used by anyone who wants to do precise calculations with floating point numbers in a decimal base.


Files included in this repository:

  • README.md - this file

  • LICENSE.md - the Michael Warren Free Software License under which this and all my other software is released

  • CoC.md - the Apolitical Code of Conduct which is used for this project

  • TODO.md - list of modifications I want to make to this software in the future

  • DOC.md - Documentation of all types and functions defined in libdfloat

  • dfloat.h: Header file containing typedefs and function prototypes

  • dfloat.c: C module containing standard dfloat functions

  • dfloat_free.c: dfloat functions that free their source operands before returning, written to facilitate more complex expressions

  • change.log: Log of changes made with each release of libdfloat

  • syntax.vim: Additional syntax highlighting for Vim users


Dependencies:

None


Installation and usage instructions:

  1. Download libdfloat using the clone feature.

  2. Run the following commands:

    gcc -c dfloat.c dfloat_free.c

    ar -rsv libdfloat.a dfloat.o dfloat_free.o

  3. To link the libdfloat library to a project, run the following command:

    gcc myproject -L dir -ldfloat

    (where dir is the directory containing libdfloat.a)


If you have any feedback or want to report any issues, please don't hesitate to notify me. You are helping me make these libraries better. This library is currently in its alpha stage and needs people to alpha-test it. Your participation is greatly appreciated.