maandree / libzahl Goto Github PK
View Code? Open in Web Editor NEWSuckless big integer library
Home Page: http://libs.suckless.org/libzahl
License: ISC License
Suckless big integer library
Home Page: http://libs.suckless.org/libzahl
License: ISC License
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.
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.
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().
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?
Please initialize i.
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 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.