Giter Site home page Giter Site logo

maandree / libzahl Goto Github PK

View Code? Open in Web Editor NEW
31.0 4.0 2.0 340 KB

Suckless big integer library

Home Page: http://libs.suckless.org/libzahl

License: ISC License

Makefile 3.10% C 65.67% Python 17.42% C++ 13.80%
c-library bigint bignum arithmetics

libzahl's Introduction

NAME
	libzahl - Big integer library

ETYMOLOGY
	The bold uppercase 'Z' which represents the set of
	all integers is derived from the german word 'Zahlen',
	whose singular is 'Zahl'.

DESCRIPTION
	libzahl is a C library for arbitrary size integers,
	that aims to be usable for robust programs, and be
	fast.

	libzahl will accomplish this by using long jumps
	when an error is detected, rather than letting the
	caller also perform a check. This shall make the
	code in the user program cleaner too. libzahl will
	use dedicated temporary bignum integers whether
	possible, and necessary, for its internal calculations.
	libzahl will not deallocate allocations, but rather
	cache them for reuse.

	With the exception of functions working with strings,
	all output parameters are before the input parameters.

RATIONALE
	GMP MP cannot be used for robust programs. LibTomMath
	is too slow, probably because of all memory allocations,
	and has a nonintuitive API. TomsFastMath has an a
	nonintuitive API, has limited precision (selected at
	compile-time), and has limited functionality. All the
	above are also bloated. Hebimath is promising, but I
	think it can be done better.

NOTES
	libzahl is currently not thread-safe.

libzahl's People

Contributors

arkamar avatar maandree avatar tosch42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

libzahl's Issues

Branch-less macros?

You may be able (probably unlikely) to sip a little more performance if you replace the logical operator in the following (from libzahl/zahl/inlines.h) with a bitwise operator. If you decide to change zzero(), there are other candidates in inlines.h worth reviewing.

ZAHL_INLINE int zzero(z_t a) { return !a->sign; }

... {return a->sign & 0;}
But, I haven't looked at the assembler code.

In the unlikely event that something is likely unlikely.

Can you provide rationale on your choices of likely() and unlikely()?

void
zsub_nonnegative_assign(z_t a, z_t b)
{
if (unlikely(zzero(b)))
zabs(a, a);
else if (unlikely(!zcmpmag(a, b)))
SET_SIGNUM(a, 0);
else
zsub_impl(a, b, b->used);
}

What if I issue zsub_nonnegative_assign(x, "0") in an iterative process? In this example, the unlikely is very, very, very unlikely (zzero(0) is not just likely, but totally likely). (I see that zsub_nonnegative_assign() may be removed.) How do these branch predictions behave if they are more likely to be incorrect than correct for certain use cases? Perhaps you could allow the user of the library a choice on the use of likely()/unlikely().

Benchmark of libzahl in fractions vs mpdecimal

I wonder how fast would it be to use fractions with high(er) number of places with libzahl as "backend" compared to using plain mpdecimal for precise calculations.

In other words, first find out how to set precision of the fractions to match the precision of mpdecimal and then benchmark some real-world (or at least artifiicial) scenarios for speed.

What would be your guess to be faster?

Doesn't Compile with C++ compilers

C++ doesn't support register and restrict.

To fix this we can use macros to only activate these keywordsin C mode and not in C++ mode.

I have a commit ready to fix this. Do you accept pull requests here on github ? Or on suckless.org ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.