Thread: Unwanted cropping occuring

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    861

    Unwanted cropping occuring

    I don't understand why this:
    Code:
    void printb( void const * addr, size_t const bits ) {
    	size_t size = bits / CHAR_BIT, b = 0;
    	uchar const *a = addr;
    	uchar val;
    	if ( bits % CHAR_BIT ) ++size;
    	while ( size-- ) {
    		for ( val = a[size]; val; val <<= 1, ++b ) {
    			if ( b == bits ) return;
    			putchar( '0' + !!(val & SCHAR_MIN) );
    		}
    	}
    }
    ...
    		putchar('\n');
    		num = test.man;
    		printb( &num, FPN_MAN_BIT );
    		putchar('\n');
    		num = mine.man;
    		printb( &num, FPN_MAN_BIT );
    		putchar('\n');
    is giving me this:
    Code:
    gcc -Wall -o "test_fpn" "test_fpn.c" && "./test_fpn"
    ...
    same = 0
    001
    01
    test.man = 0000000200000 mine.man = 0000000400000 exp t = 082 m = 081 sig t = 0 m = 0 fpn t = 1.000000e+01 m = 6.000000e+00 value '1e+1'
    same = 0
    0011111101111001
    011111
    test.man = 00000003EBC20 mine.man = 0000000788000 exp t = 099 m = 090 sig t = 0 m = 0 fpn t = 1.000000e+08 m = 2.544640e+05 value '1e+8'
    same = 0
    00010101000000111111001
    00101111101
    test.man = 00000001502F9 mine.man = 00000002FA000 exp t = 0A0 m = 094 sig t = 0 m = 0 fpn t = 1.000000e+10 m = 2.877440e+06 value '1e+10'
    Compilation finished successfully.
    Don't mind the mantissa itself, I was trying to see what was the results of various attempts, gotta leave for work soon so would like to fix this particular issue before I do.

    Edit: Never mind, figured it out, I forgot I needed to set the break condition as a seperate variable, I declared a new variable "bit" and just reset to 1 on each start of the loop and shifted it just like num but instead of testing if num was empty tested if bit was empty.
    Last edited by awsdert; 11-15-2019 at 05:53 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Occuring symbol per line
    By Veselin Lalov in forum C Programming
    Replies: 2
    Last Post: 12-17-2014, 07:55 PM
  2. Problem occuring with C++ (OpenGL)
    By luckygirl in forum C++ Programming
    Replies: 2
    Last Post: 04-26-2013, 03:27 AM
  3. Cropping Images
    By mx781 in forum C++ Programming
    Replies: 2
    Last Post: 07-09-2007, 02:05 PM
  4. Bitmap Cropping#2
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 10-10-2006, 07:38 AM

Tags for this Thread