Deleted macros

This commit is contained in:
Nicolás A. Ortega 2016-12-10 17:11:21 +01:00
parent a782bdb57d
commit dab78093ab
No known key found for this signature in database
GPG Key ID: 614272579C2070D1
3 changed files with 7 additions and 14 deletions

View File

@ -2,8 +2,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "optimizers.h"
/** /**
* This is the number of elements by which the list expands. * This is the number of elements by which the list expands.
* WARNING: Always use doubles for this number (2^X) * WARNING: Always use doubles for this number (2^X)
@ -28,14 +26,14 @@ void deInitList(List *l) {
} }
void addToList(List *l, mpz_t n) { void addToList(List *l, mpz_t n) {
if(unlikely(l->end == l->size)) { if(l->end == l->size) {
l->size += BLOCK_SIZE; l->size += BLOCK_SIZE;
if(unlikely(l->size == 0)) { if(l->size == 0) {
fprintf(stderr, "`l->size' has overflowed!\n"); fprintf(stderr, "`l->size' has overflowed!\n");
exit(1); exit(1);
} }
void *tmp = realloc(l->list, sizeof(mpz_t) * l->size); void *tmp = realloc(l->list, sizeof(mpz_t) * l->size);
if(unlikely(!tmp)) { if(!tmp) {
fprintf(stderr, "Failed to allocate more memory to list!\n"); fprintf(stderr, "Failed to allocate more memory to list!\n");
exit(1); exit(1);
} }

View File

@ -6,13 +6,12 @@
#include "list.h" #include "list.h"
#include "types.h" #include "types.h"
#include "optimizers.h"
static bool run; static bool run;
void leave(); void leave();
int main(void) { int main(void) {
printf("Indivisible v0.2\n"); puts("Indivisible v0.2\n");
// Quit on ^C by setting `run = false' // Quit on ^C by setting `run = false'
run = true; run = true;
@ -44,9 +43,8 @@ int main(void) {
// Calculate half of `num' // Calculate half of `num'
mpz_fdiv_q_ui(halfNum, num, 2); mpz_fdiv_q_ui(halfNum, num, 2);
// Loop through found primes // Loop through found primes
for(ulli i = 0; i < primes.size; ++i) { // Skip 2 because we're skipping even nymbers
// If the prime we're looking at is >= half of `num' then we can skip the rest for(ulli i = 1; mpz_cmp(primes.list[i], halfNum) >= 0; ++i) {
if(mpz_cmp(primes.list[i], halfNum) >= 0) break;
// If `num' is divisible by a prime then go to the next number // If `num' is divisible by a prime then go to the next number
if(mpz_divisible_p(num, primes.list[i]) != 0) if(mpz_divisible_p(num, primes.list[i]) != 0)
goto nextPrime; goto nextPrime;
@ -74,6 +72,6 @@ nextPrime:
} }
void leave() { void leave() {
printf("Exiting...\n"); puts("Exiting...\n");
run = false; run = false;
} }

View File

@ -1,3 +0,0 @@
#pragma once
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)