Thread: I can't spot my mistake...

  1. #211
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,231
    Quote Originally Posted by JaredPuffin View Post
    Thank You!
    Finaly a nice and angumented answer
    Yeaaah, thing is I already did that before I started, doesn't mean I get a full understanding from documents alone, sometimes you just have to get on with failing a few dozen times before you finally understand correctly (especially if what you're dealing with doesn't a nice fixed size like they where working with)

  2. #212
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,231
    Gotta get ready for work so will just dump the code and output for now (uploaded all code to alu project on github just now so can search through that whilst waiting for me to get a chance to repond to questions)
    Code:
    int_t alup__neg_int( alup_t const * const _SRC )
    {
    	int ret = alup_not( _SRC );
    	
    	if ( ret == 0 )
    		return alup__inc_int( _SRC );
    		
    	alu_error( ret );
    	return ret;
    }
    
    int_t alup_neg( alup_t const * const _SRC )
    {
    	if ( alup_floating( _SRC ) )
    	{
    		alup_t _MAN;
    		alub_t sign = alup_final_bit( _SRC );
    		bool_t neg = !(*(sign.ptr) & sign.mask);
    		
    		*(sign.ptr) &= ~(sign.mask);
    		*(sign.ptr) |= IFTRUE( neg, sign.mask );
    		
    		alup_init_mantissa( _SRC, _MAN );
    		
    		return alup__neg_int( &_MAN );
    	}
    	
    	return alup__neg_int( _SRC );
    }
    Code:
    make check.run
    ...
    Running suite(s): ALU
    ../tests/check_alu.c:670: test_alup_op1_floating_incremental_fn() 192, -(192.000000) = -192.000000, got 192.000000
    ../tests/check_alu.c:680: test_alup_op1_floating_incremental_fn() &_TESTNO = 0 000'0000'0000'0000'0000'0000'1100'0000
    ../tests/check_alu.c:681: test_alup_op1_floating_incremental_fn() &_BEFORE = 0 +0007 10000110 100'0000'0000'0000'0000'0000
    ../tests/check_alu.c:682: test_alup_op1_floating_incremental_fn() &_EXPECT = 1 +0007 10000110 100'0000'0000'0000'0000'0000
    ../tests/check_alu.c:683: test_alup_op1_floating_incremental_fn() &_RESULT = 0 +0007 10000110 100'0000'0000'0000'0000'0000
    99%: Checks: 3561, Failures: 1, Errors: 0
    ...
    Compilation finished successfully.

  3. #213
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,231
    Quote Originally Posted by awsdert View Post
    Gotta get ready for work so will just dump the code and output for now (uploaded all code to alu project on github just now so can search through that whilst waiting for me to get a chance to repond to questions)
    Code:
    int_t alup__neg_int( alup_t const * const _SRC )
    {
    	int ret = alup_not( _SRC );
    	
    	if ( ret == 0 )
    		return alup__inc_int( _SRC );
    		
    	alu_error( ret );
    	return ret;
    }
    
    int_t alup_neg( alup_t const * const _SRC )
    {
    	if ( alup_floating( _SRC ) )
    	{
    		alup_t _MAN;
    		alub_t sign = alup_final_bit( _SRC );
    		bool_t neg = !(*(sign.ptr) & sign.mask);
    		
    		*(sign.ptr) &= ~(sign.mask);
    		*(sign.ptr) |= IFTRUE( neg, sign.mask );
    		
    		alup_init_mantissa( _SRC, _MAN );
    		
    		return alup__neg_int( &_MAN );
    	}
    	
    	return alup__neg_int( _SRC );
    }
    Code:
    make check.run
    ...
    Running suite(s): ALU
    ../tests/check_alu.c:670: test_alup_op1_floating_incremental_fn() 192, -(192.000000) = -192.000000, got 192.000000
    ../tests/check_alu.c:680: test_alup_op1_floating_incremental_fn() &_TESTNO = 0 000'0000'0000'0000'0000'0000'1100'0000
    ../tests/check_alu.c:681: test_alup_op1_floating_incremental_fn() &_BEFORE = 0 +0007 10000110 100'0000'0000'0000'0000'0000
    ../tests/check_alu.c:682: test_alup_op1_floating_incremental_fn() &_EXPECT = 1 +0007 10000110 100'0000'0000'0000'0000'0000
    ../tests/check_alu.c:683: test_alup_op1_floating_incremental_fn() &_RESULT = 0 +0007 10000110 100'0000'0000'0000'0000'0000
    99%: Checks: 3561, Failures: 1, Errors: 0
    ...
    Compilation finished successfully.
    Turned out to be as simple as a noob mistake on length handling, renamed a parameter of alup_t to make it less likely I'll make that mistake in future, finally got back to FPN math bugs, current one is in multiplication though that is probably due to a change I made in alup.h after noticing my mistake, I'll check another day as I will soon go to bed

  4. #214
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,231
    slightly off topic though still important for the ALU, finally found an example of those annoyingly complex math formulas for random numbers converted into code, tried my own variant (just a change in numbers) which seems to produce the static for a *.ppm file but when I tried to install dieharder to test the quality the only accessible one was from the AUR which isn't linking due to multiple definitions of symbols, can someone with dieharder compile the attached file and post the results please.
    In case you wanna play with the code the main function to consider is this one:
    Code:
    size_t rng( size_t seed )
    {
    #if 0
    	/* Lehmer method */
    	size_t base = seed + 0xE120FC15;
    	size_t temp = base * 0x4A39b70D;
    	size_t num1 = (temp >> 32) ^ temp;
    	temp = num1 * 0x12FAD5C9;
    	return (temp >> 32) ^ temp;
    #else
    	size_t base = seed + 0xEA57;
    	size_t temp = base * 0xDEAD;
    	size_t num1 = (temp >> (bitsof(size_t)/2)) ^ temp;
    	temp = num1 * 0xC0DE;
    	return (temp >> (bitsof(size_t)/2)) ^ temp;
    #endif
    }
    the original code I saw was for 32 bit numbers which somehow worked for 64 bit but I wanted 16bit compatible also hence the shorter numbers and a calculation of bits to move by
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can anyone help to spot mistake in the code
    By chess_queen in forum C Programming
    Replies: 1
    Last Post: 10-21-2012, 10:37 AM
  2. Can you spot my mistake?
    By Brewer in forum C Programming
    Replies: 13
    Last Post: 11-12-2006, 12:50 PM
  3. going to a certain spot in a file...
    By agerealm in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2002, 02:31 AM

Tags for this Thread