int main(void) { checkDivide(0.0f); checkDivide(-0.0f); printf("\n"); checkDivide(FLT_MIN); checkDivide(FLT_MIN/4.0f); /* denormalized or subnormal floating point */ printf("\n"); checkDivide(FLT_MAX); checkDivide(INFINITY); checkDivide(-INFINITY); checkDivide(NAN); return 0; }
void* getmem(uintptr_t size) { if (size <= 0) { return NULL; } //Create new size slightly larger then specified size int new_size = (size/16.0 + 1)*16; //If the list is empty, acquire new memory block if (list == NULL && new_size < NEW_BLOCK_SIZE) { acquire_new_Block(NEW_BLOCK_SIZE); } else if (list == NULL && new_size >= NEW_BLOCK_SIZE) { acquire_new_Block(new_size); } free_list *current = list; //Check if the first free_list block is large enough if ((current -> size) >= new_size) { if (checkDivide((int)(current -> size), new_size)) { free_list *newlist = (free_list*)((uintptr_t)current + (current->size) - new_size); newlist -> size = new_size; newlist -> next = NULL; current -> size = (current -> size) - new_size; return newlist; } else { list = NULL; current -> next = NULL; return current; } } free_list *previous = current; //find the free_list block that is large enough while (((current -> next) != NULL) && ((current -> size) < new_size)) { previous = current; current = current -> next; } if ((current -> size) < new_size) { if (new_size < NEW_BLOCK_SIZE) { acquire_new_Block(NEW_BLOCK_SIZE); } else if (new_size >= NEW_BLOCK_SIZE) { acquire_new_Block(new_size); } current = current -> next; } if (checkDivide((int)(current -> size), new_size)) { free_list *newlist = (free_list*)((uintptr_t)current + (current->size) - new_size); newlist -> size = new_size; newlist -> next = NULL; current -> size = (current -> size) - new_size; return newlist; } else { previous -> next = current -> next; current -> next = NULL; return current; } }