NO

Recent Posts

Pages: [1] 2 3 ... 10
1
User contributions / Re: Big integer arithmetic library
« Last post by cosh on Today at 01:27:04 PM »
hello cosh  :)
I ran your test, if compiled with -O2 the time was about .0043, if compiled with -O3 .0058, it's not uncommon that -O3 is a bit slower than -O2
but I don't like the license at all, LGPL for a library is ok but not GPL, although I much prefer the MIT type of license

Yes, it is unusually that -O3 optimization shows a poorer speed than -O2.
I will consider altering license after your notice in the future. Thank you. Now, I think GPLv3 is better for this library.
2
User contributions / Re: Big integer arithmetic library
« Last post by cosh on Today at 01:22:07 PM »
hello cosh
if you implement a multiply BigInt by 32-bit integer then your factorial would be about 3 times faster

Hello, jack
In the file pbk.h there are some macros to define block integers:
/* Predefined data type. */
typedef int                _ib;      /* Integer block. */
typedef unsigned int       _ub;      /* Unsigned integer block. */
typedef long long          _idb;     /* Integer double block. */
typedef unsigned long long _udb;     /* Unsigned integer double block. */

On a 64-bit machine, int usually be a 32bits integer.
3
User contributions / Re: Big integer arithmetic library
« Last post by cosh on Today at 01:19:37 PM »
pbint.def
Code: [Select]
LIBRARY pbint.dll
EXPORTS
pbkInitBint
pbkReallocBint
pbkFreeBint
pbkCreateBint
pbkDeleteBint
pbkMoveBint
pbkCopyBint
pbkIbToBint
pbkBintToIb
pbkCompareBint
pbkAddBint
pbkSubtractBint
pbkLeftShiftBint
pbkRightShiftBint
pbkMultiplyBint
pbkDivideBint
pbkInitBnum
pbkReallocBnum
pbkFreeBnum
pbkCreateBnum
pbkDeleteBnum
pbkMoveBnum
pbkIbToBnum
pbkDecimalSzToBnum
pbkPrintBnum
pbkBintToDecimalBnum
pbkDecimalBnumToBint
pbmBintPower
pbmUbFactorial
pbmBintSquareRoot
pbmBintGreatestCommonDivisor
pbxLoadBint
pbxSaveBint

Hi, TimoVJL
Thanks for your def file, it is useful to export functions for a dll.
4
User contributions / Re: Big integer arithmetic library
« Last post by jack on Yesterday at 04:53:55 PM »
hello cosh
if you implement a multiply BigInt by 32-bit integer then your factorial would be about 3 times faster
5
User contributions / Re: Big integer arithmetic library
« Last post by jack on Yesterday at 02:44:35 PM »
hello cosh  :)
I ran your test, if compiled with -O2 the time was about .0043, if compiled with -O3 .0058, it's not uncommon that -O3 is a bit slower than -O2
but I don't like the license at all, LGPL for a library is ok but not GPL, although I much prefer the MIT type of license
6
User contributions / Re: Big integer arithmetic library
« Last post by TimoVJL on Yesterday at 09:09:44 AM »
pbint.def
Code: [Select]
LIBRARY pbint.dll
EXPORTS
pbkInitBint
pbkReallocBint
pbkFreeBint
pbkCreateBint
pbkDeleteBint
pbkMoveBint
pbkCopyBint
pbkIbToBint
pbkBintToIb
pbkCompareBint
pbkAddBint
pbkSubtractBint
pbkLeftShiftBint
pbkRightShiftBint
pbkMultiplyBint
pbkDivideBint
pbkInitBnum
pbkReallocBnum
pbkFreeBnum
pbkCreateBnum
pbkDeleteBnum
pbkMoveBnum
pbkIbToBnum
pbkDecimalSzToBnum
pbkPrintBnum
pbkBintToDecimalBnum
pbkDecimalBnumToBint
pbmBintPower
pbmUbFactorial
pbmBintSquareRoot
pbmBintGreatestCommonDivisor
pbxLoadBint
pbxSaveBint
7
User contributions / Re: Big integer arithmetic library
« Last post by WiiLF23 on Yesterday at 03:33:01 AM »
Nice work! Very appreciated.

Cheers!
8
User contributions / Re: Big integer arithmetic library
« Last post by frankie on May 20, 2024, 10:58:59 PM »
 :)
9
User contributions / Big integer arithmetic library
« Last post by cosh on May 20, 2024, 07:14:08 PM »
 :) Hi, there
I wrote a library for big integer arithmetic here: https://github.com/coshcage/pbint
It's called pbint means portable big integer library.
The difference between pbint and gnu gmp is that you don't need to control memory manually in pbint, pbint combined heap memory management functions to arithmetic functions together. pbint is smaller and faster. If you are interested in high precision calculation and large integer arithmetic, pbint is suitable for you.

I also tested and compiled pbint with Pelles C compiler. Before compiling pbint with Pelles C you need to alter pbint according to the following instructions:
Delete line 568 register qualifier in pbk.c.
Delete line 621 register qualifier in pbk.c. But don't delete variable declaration clause.

Testing shows to calculate factorial 2000 on an Intel Core i9 9 Gen microprocessor only needs 0.01 seconds.
Here's the code that I used for testing:
Code: [Select]
#include <stdio.h>
#include <Windows.h>
#include "pbk.h"
#include "pbm.h"

int main()
{
P_BINT pc;
P_BNUM p;
LARGE_INTEGER la, lb, lc;


pc = pbkCreateBint(0);
p = pbkCreateBnum(10);

QueryPerformanceFrequency(&lc);
QueryPerformanceCounter(&la);

pbmUbFactorial(pc, 2000); // 2000!

QueryPerformanceCounter(&lb);
printf("%lf\n", (double)(lb.QuadPart - la.QuadPart) / (double)lc.QuadPart);

pbkBintToDecimalBnum(p, pc);

pbkPrintBnum(p);

return 0;
}

Kind regards,
Cosh.
10
Tips & tricks / KAST macro by MrBcx
« Last post by Vortex on May 18, 2024, 09:28:17 PM »
A nice macro by MrBcx used in the BCX language.

Traditional type casting :

Code: [Select]
#include <windows.h>
#include <stdio.h>

int main(void)
{
HMODULE hMod;
PIMAGE_NT_HEADERS pNThdr;
PIMAGE_EXPORT_DIRECTORY pDesc;
DWORD NumbOfNames,i;
DWORD* AddrOfNames;

hMod=LoadLibrary("kernel32.dll");

pNThdr=(PIMAGE_NT_HEADERS)((LPBYTE)hMod + ((PIMAGE_DOS_HEADER)hMod)->e_lfanew);

pDesc=(PIMAGE_EXPORT_DIRECTORY)((LPBYTE)hMod + pNThdr->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);

NumbOfNames =  pDesc -> NumberOfNames;

AddrOfNames = (DWORD *)((LPBYTE)hMod + pDesc -> AddressOfNames);

for(i=0;i<NumbOfNames;i++)
{
printf("%s\n",(*AddrOfNames+(LPBYTE)hMod));

AddrOfNames=AddrOfNames+1;
}

FreeLibrary(hMod);
return 0;
}

The KAST macro for type casting :

Code: [Select]
#include <windows.h>
#include <stdio.h>

/* KAST macro by MrBcx */

#define KAST(to_type,old_obj) ((to_type)(old_obj))

int main(void)
{
HMODULE hMod;
PIMAGE_NT_HEADERS pNThdr;
PIMAGE_EXPORT_DIRECTORY pDesc;
DWORD NumbOfNames,i;
DWORD* AddrOfNames;

hMod=LoadLibrary("kernel32.dll");

pNThdr=KAST(PIMAGE_NT_HEADERS,KAST(LPBYTE,hMod) + KAST(PIMAGE_DOS_HEADER,hMod)->e_lfanew);

pDesc=KAST(PIMAGE_EXPORT_DIRECTORY,KAST(LPBYTE,hMod) + pNThdr->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);

NumbOfNames =  pDesc -> NumberOfNames;

AddrOfNames = KAST(DWORD *,KAST(LPBYTE,hMod) + pDesc -> AddressOfNames);

for(i=0;i<NumbOfNames;i++)
{
printf("%s\n",*AddrOfNames+KAST(LPBYTE,hMod));

AddrOfNames=AddrOfNames+1;
}

FreeLibrary(hMod);
return 0;
}
Pages: [1] 2 3 ... 10