Skip to content

Instantly share code, notes, and snippets.

@MarekKnapek
Last active November 20, 2023 04:55
Show Gist options
  • Save MarekKnapek/f221b604fd96d2fc0ac4ec6a4fd406a6 to your computer and use it in GitHub Desktop.
Save MarekKnapek/f221b604fd96d2fc0ac4ec6a4fd406a6 to your computer and use it in GitHub Desktop.
Fib500
#define mk_lang_jumbo_want 1
/* You need my library from https://github.com/marekKnapek/mk_clib for this. */
#include "mk_sl_uint32.h"
#include "mk_lang_div_roundup.h"
#define mk_sl_cui_t_name big_fib
#define mk_sl_cui_t_base mk_sl_cui_uint32
#define mk_sl_cui_t_count mk_lang_div_roundup(346, 32)
#include "mk_sl_cui_inl_fileh.h"
#include "mk_sl_cui_inl_filec.h"
#include <assert.h>
#include <stdio.h>
big_fib_t fibonacci(int n)
{
big_fib_t a;
big_fib_t b;
big_fib_t c;
big_fib_pt pa;
big_fib_pt pb;
big_fib_pt pc;
big_fib_pt t;
int i;
assert(n >= 2);
pa = &a;
pb = &b;
pc = &c;
big_fib_set_zero(pa);
big_fib_set_one(pb);
big_fib_add3_wrap_cid_cod(pa, pb, pc);
for(i = 0; i != n - 2; ++i)
{
t = pa;
pa = pb;
pb = pc;
pc = t;
big_fib_add3_wrap_cid_cod(pa, pb, pc);
}
return *pc;
}
int main()
{
big_fib_t f;
char str[big_fib_strlendec_v];
int len;
f = fibonacci(500);
len = big_fib_to_str_dec_n(&f, &str[0], big_fib_strlendec_v);
printf("%.*s", len, &str[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment