Can someone help me with FPN division please?

I'll start by referencing the original thread I posted this problem in
https://cboard.cprogramming.com/c-programming/179473-i-cant-spot-my-mistake.html

Basically I've been programming a ALU inspired bignum library, gotten all bignum integer math working, gotten FPN addition, subtraction & multiplication working also, but now I'm struggling to get the division part working. The project is linked [url=https://github.com/awsdert/alu]here[/url] and the code for the function I'm using is below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
int_t alup__div( alup_t _NUM, alup_t _VAL, void *_rem, void *_tmp )
{
	if ( alup_floating( _NUM ) || alup_floating( _VAL ) )
	{
		int_t ret;
		alup_t _DST, _SRC, _DMAN, _SMAN;
		ssize_t dexp, sexp, dbias, sbias, dbits, sbits, bits, size;
		bool_t dneg, sneg;
		
		/* Ensure dealing with just floats, impossible for both to take _tmp
		 * given the above if statment */
		
		if ( alup_floating( _NUM ) )
		{
			_DST = _NUM;
		}
		else
		{
			bits = _NUM.upto - _NUM.from;
			size = BITS2SIZE( bits );
			alup_init_floating( _DST, _tmp, size );
			alup_mov( _DST, _NUM );
		}
		
		if ( alup_floating( _VAL ) )
		{
			_SRC = _VAL;
		}
		else
		{
			bits = _VAL.upto - _VAL.from;
			size = BITS2SIZE( bits );
			alup_init_floating( _SRC, _tmp, size );
			alup_mov( _SRC, _VAL );
		}
		
		dneg = alup_below0( _DST );
		sneg = alup_below0( _SRC );
		alub_set( _DST.data, _DST.upto - 1, dneg != sneg );
		
		dexp = alup_get_exponent( _DST );
		sexp = alup_get_exponent( _SRC );
		
		if ( !dexp || !sexp )
		{
			_NUM.upto--;
			alup_set( _NUM, 0 );
			return 0;
		}
		
		dbias = alup_get_exponent_bias( _DST );
		dexp -= dbias;
		
		sbias = alup_get_exponent_bias( _DST );
		sexp -= sbias;
				
		alup_init_mantissa( _DST, _DMAN );
		alup_init_mantissa( _SRC, _SMAN );
		
		dbits = _DMAN.upto - _DMAN.from;
		sbits = _SMAN.upto - _SMAN.from;
		bits = LOWEST( dbits, sbits );
		
		_SMAN.from = _SMAN.upto - EITHER( sexp >= 0 && sexp < bits, sexp, bits );
		
		alub_set( _DMAN.data, _DMAN.upto, 1 );
		alub_set( _SMAN.data, _SMAN.upto, 1 );
		_DMAN.upto++;
		_SMAN.upto++;
		
		ret = alup__div_int2int( _DMAN, _SMAN, _rem );
		
		_DMAN.upto--;
		_SMAN.upto--;
		
		/* We mangled this so restore it now */
		alup_set_exponent( _SRC, sexp + sbias );

#if 1
		if ( ret == EOVERFLOW )
		{
			dexp--;
			//alup__shr( _DMAN, 1 );
			//alub_set( _DMAN.data, _DMAN.upto - 1, 1 );
		}
#endif
		
		dexp -= sexp;
		if ( dexp > dbias )
		{	
			/* Set infinity */
			alup_set_exponent( _DST, (dbias << 1) | 1 );
			alup_set( _DMAN, 0 );
		}
		else
		{
			alup_set_exponent( _DST, dexp + dbias );
		}
		
		if ( alup_floating( _NUM ) )
			return 0;
			
		return alup_mov( _NUM, _DST );
	}
	
	return alup__div_int2int( _NUM, _VAL, _rem );
}

The test I'm using for it (using https://libcheck.github.io/check/):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
START_TEST( test_alup_div_floating )
{
	ck_assert( alu_upto(alu) > 0 );
	
	ullong_t _num = _i, _val = 3;
	double tmp_num, tmp_val
		, src_num = _num
		, src_val = _val
		, got_num = _num
		, got_val = _val
		, expect = _num
		, result = _num;
	alup_t _RESULT, _GOT_VAL;
	
	alup_init_floating( _RESULT, &result, sizeof(double) );
	alup_init_floating( _GOT_VAL, &got_val, sizeof(double) );
	
	expect /= src_val;
	(void)alup__div( _RESULT, _GOT_VAL, &tmp_num, &tmp_val );
	
	if ( memcmp( &result, &expect, sizeof(double) ) != 0 )
	{
		alup_t _EXP, _MAN, _EXPECT, _GOT_NUM, _SRC_NUM, _SRC_VAL;
		
		alup_init_floating( _EXPECT, &expect, sizeof(double) );
		alup_init_floating( _SRC_NUM, &src_num, sizeof(double) );
		alup_init_floating( _SRC_VAL, &src_val, sizeof(double) );
		alup_init_floating( _GOT_NUM, &got_num, sizeof(double) );
		alup_init_exponent( _GOT_NUM, _EXP );
		alup_init_mantissa( _GOT_NUM, _MAN );
		
		alu_printf
		(
			"_num = %llu, _val = %llu, "
			"(_EXP.upto = %zu) - (_EXP.from = %zu) = %zu, "
			"(_MAN.upto = %zu) - (_MAN.from = %zu) = %zu"
			, _num
			, _val
			, _EXP.upto, _EXP.from, _EXP.upto - _EXP.from
			, _MAN.upto, _MAN.from, _MAN.upto - _MAN.from
		);
		
		alup_print( _EXPECT, 0, 1 );
		alup_print( _RESULT, 0, 1 );
		alup_print( _GOT_NUM, 0, 1 );
		alup_print( _SRC_NUM, 0, 1 );
		alup_print( _GOT_VAL, 0, 1 );
		alup_print( _SRC_VAL, 0, 1 );
	}
	
	ck_assert( memcmp( &result, &expect, sizeof(double) ) == 0 );
}
END_TEST

Output was apparently too long for this post so will do another for that one
Edited output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
make check.run
...
Running suite(s): ALU
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 3, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0000 01111111111 0000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0000 01111111111 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1469: test_alup_div_floating_fn() _GOT_NUM = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1470: test_alup_div_floating_fn() _SRC_NUM = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1471: test_alup_div_floating_fn() _GOT_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1472: test_alup_div_floating_fn() _SRC_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 5, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0000 01111111111 1010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0000 01111111111 0110101010101010101010101010101010101010101010101010
../tests/check_alu.c:1469: test_alup_div_floating_fn() _GOT_NUM = 0 +0002 10000000001 0100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1470: test_alup_div_floating_fn() _SRC_NUM = 0 +0002 10000000001 0100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1471: test_alup_div_floating_fn() _GOT_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1472: test_alup_div_floating_fn() _SRC_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 6, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 0000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1469: test_alup_div_floating_fn() _GOT_NUM = 0 +0002 10000000001 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1470: test_alup_div_floating_fn() _SRC_NUM = 0 +0002 10000000001 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1471: test_alup_div_floating_fn() _GOT_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1472: test_alup_div_floating_fn() _SRC_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 7, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 0010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0000 01111111111 1001010101010101010101010101010101010101010101010101
../tests/check_alu.c:1469: test_alup_div_floating_fn() _GOT_NUM = 0 +0002 10000000001 1100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1470: test_alup_div_floating_fn() _SRC_NUM = 0 +0002 10000000001 1100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1471: test_alup_div_floating_fn() _GOT_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1472: test_alup_div_floating_fn() _SRC_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 9, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0110000000000000000000000000000000000000000000000000
../tests/check_alu.c:1469: test_alup_div_floating_fn() _GOT_NUM = 0 +0003 10000000010 0010000000000000000000000000000000000000000000000000
../tests/check_alu.c:1470: test_alup_div_floating_fn() _SRC_NUM = 0 +0003 10000000010 0010000000000000000000000000000000000000000000000000
../tests/check_alu.c:1471: test_alup_div_floating_fn() _GOT_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1472: test_alup_div_floating_fn() _SRC_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 10, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 1010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 0110101010101010101010101010101010101010101010101010
../tests/check_alu.c:1469: test_alup_div_floating_fn() _GOT_NUM = 0 +0003 10000000010 0100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1470: test_alup_div_floating_fn() _SRC_NUM = 0 +0003 10000000010 0100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1471: test_alup_div_floating_fn() _GOT_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1472: test_alup_div_floating_fn() _SRC_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 11, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 1101010101010101010101010101010101010101010101010101
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 0111010101010101010101010101010101010101010101010101
../tests/check_alu.c:1469: test_alup_div_floating_fn() _GOT_NUM = 0 +0003 10000000010 0110000000000000000000000000000000000000000000000000
../tests/check_alu.c:1470: test_alup_div_floating_fn() _SRC_NUM = 0 +0003 10000000010 0110000000000000000000000000000000000000000000000000
../tests/check_alu.c:1471: test_alup_div_floating_fn() _GOT_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1472: test_alup_div_floating_fn() _SRC_VAL = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
...
97%: Checks: 1877, Failures: 46, Errors: 0
../tests/check_alu.c:1475:F:Core:test_alup_div_floating:3: Assertion 'memcmp( &result, &expect, sizeof(double) ) == 0' failed
...
../tests/check_alu.c:1475:F:Core:test_alup_div_floating:52: Assertion 'memcmp( &result, &expect, sizeof(double) ) == 0' failed
Compilation finished successfully.
Last edited on
Mantissa is now closer to always being correct but still need help:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
int_t alup__div( alup_t _NUM, alup_t _VAL, void *_rem, void *_tmp )
{
	if ( alup_floating( _NUM ) || alup_floating( _VAL ) )
	{
		int_t ret;
		alup_t _DST, _SRC, _DMAN, _SMAN;
		ssize_t exp, dexp, sexp, dbias, sbias, dbits, sbits, bits, size;
		bool_t dneg, sneg;
		
		/* Ensure dealing with just floats, impossible for both to take _tmp
		 * given the above if statment */
		
		if ( alup_floating( _NUM ) )
		{
			_DST = _NUM;
		}
		else
		{
			bits = _NUM.upto - _NUM.from;
			size = BITS2SIZE( bits );
			alup_init_floating( _DST, _tmp, size );
			alup_mov( _DST, _NUM );
		}
		
		if ( alup_floating( _VAL ) )
		{
			_SRC = _VAL;
		}
		else
		{
			bits = _VAL.upto - _VAL.from;
			size = BITS2SIZE( bits );
			alup_init_floating( _SRC, _tmp, size );
			alup_mov( _SRC, _VAL );
		}
		
		dneg = alup_below0( _DST );
		sneg = alup_below0( _SRC );
		alub_set( _DST.data, _DST.upto - 1, dneg != sneg );
		
		dexp = alup_get_exponent( _DST );
		sexp = alup_get_exponent( _SRC );
		
		if ( !dexp || !sexp )
		{
			_NUM.upto--;
			alup_set( _NUM, 0 );
			return 0;
		}
		
		dbias = alup_get_exponent_bias( _DST );
		dexp -= dbias;
		
		sbias = alup_get_exponent_bias( _DST );
		sexp -= sbias;
				
		alup_init_mantissa( _DST, _DMAN );
		alup_init_mantissa( _SRC, _SMAN );
		
		dbits = _DMAN.upto - _DMAN.from;
		sbits = _SMAN.upto - _SMAN.from;
		bits = LOWEST( dbits, sbits );
		
		_SMAN.from = _SMAN.upto - EITHER( sexp >= 0 && sexp < bits, sexp, bits );
		
		alub_set( _DMAN.data, _DMAN.upto, 1 );
		alub_set( _SMAN.data, _SMAN.upto, 1 );
		_DMAN.upto++;
		_SMAN.upto++;
		
		ret = alup__div_int2int( _DMAN, _SMAN, _rem );
		
		/* We mangled this so restore it now */
		alup_set_exponent( _SRC, sexp + sbias );

#if 1
		if ( ret == EOVERFLOW )
		{
			dexp--;
			//alup__shr( _DMAN, 1 );
			//alub_set( _DMAN.data, _DMAN.upto - 1, 1 );
		}
#endif
		
		exp = dexp - sexp;
		if ( exp > dbias )
		{	
			/* Set infinity */
			alup_set( _DMAN, 0 );
			alup_set_exponent( _DST, (dbias << 1) | 1 );
		}
		else if ( exp <= (ssize_t)(_DMAN.upto - _DMAN.from) )
		{
			alub_t e = alup_end_bit( _DMAN );
			exp = (_DMAN.upto - e.bit) - 1;
			alup__shl( _DMAN, exp );
			alup_set_exponent( _DST, (dexp - sexp) + dbias );
		}	
		else
		{
			alup_set_exponent( _DST, exp + dbias );
		}
		
		_DMAN.upto--;
		_SMAN.upto--;
		
		if ( alup_floating( _NUM ) )
			return 0;
			
		return alup_mov( _NUM, _DST );
	}
	
	return alup__div_int2int( _NUM, _VAL, _rem );
}
Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
make check.run
...
Running suite(s): ALU
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 1, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 -0002 01111111101 0101010101010101010101010101010101010101010101010101
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 -0002 01111111101 0101010101010101010101010101010101010101010101010100
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 2, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 -0001 01111111110 0101010101010101010101010101010101010101010101010101
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 -0001 01111111110 0101010101010101010101010101010101010101010101010100
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 4, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0000 01111111111 0101010101010101010101010101010101010101010101010101
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0000 01111111111 0101010101010101010101010101010101010101010101010100
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 5, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0000 01111111111 1010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0000 01111111111 1010101010101010101010101010101010101010101010101000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 7, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 0010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0000 01111111111 0010101010101010101010101010101010101010101010101010
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 8, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 0101010101010101010101010101010101010101010101010101
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 0101010101010101010101010101010101010101010101010100
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 9, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 10, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 1010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 1010101010101010101010101010101010101010101010101000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 11, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 1101010101010101010101010101010101010101010101010101
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 1101010101010101010101010101010101010101010101010100
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 13, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 0001010101010101010101010101010101010101010101010101
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 0001010101010101010101010101010101010101010101010100
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 14, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 0010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 0010101010101010101010101010101010101010101010101010
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 16, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 0101010101010101010101010101010101010101010101010101
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0101010101010101010101010101010101010101010101010100
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 17, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 0110101010101010101010101010101010101010101010101011
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0110101010101010101010101010101010101010101010101000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 18, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0003 10000000010 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 19, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1001010101010101010101010101010101010101010101010101
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 1001010101010101010101010101010101010101010101010100
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 20, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 1010101010101010101010101010101010101010101010101000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 21, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0003 10000000010 1100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 22, _val = 3, (_EXP.upto = 63) - (_EXP.from = 52) = 11, (_MAN.upto = 52) - (_MAN.from = 0) = 52
../tests/check_alu.c:1467: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1101010101010101010101010101010101010101010101010101
../tests/check_alu.c:1468: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 1101010101010101010101010101010101010101010101010100
...
97%: Checks: 1877, Failures: 43, Errors: 0
../tests/check_alu.c:1477:F:Core:test_alup_div_floating:1: Assertion 'memcmp( &result, &expect, sizeof(double) ) == 0' failed
...
Compilation finished successfully.
Got this far now:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
make check.run
...
Running suite(s): ALU
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 5, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0000 01111111111 1010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0000 01111111111 1010101010101010101010101010101010101010101010101010
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 7, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 0010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0000 01111111111 0010101010101010101010101010101010101010101010101010
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 9, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 1000000000000000000000000000000000000000000000000000
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 10, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 1010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 1010101010101010101010101010101010101010101010101010
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 13, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 0001010101010101010101010101010101010101010101010101
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 0001010101010101010101010101010101010101010101010101
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 14, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 0010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 0010101010101010101010101010101010101010101010101010
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 17, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 0110101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0110101010101010101010101010101010101010101010101010
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 18, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0003 10000000010 1000000000000000000000000000000000000000000000000000
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 20, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 1010101010101010101010101010101010101010101010101010
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 21, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0003 10000000010 1100000000000000000000000000000000000000000000000000
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 23, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1110101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 1110101010101010101010101010101010101010101010101010
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 25, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0000101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0000101010101010101010101010101010101010101010101010
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 26, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0001010101010101010101010101010101010101010101010101
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0001010101010101010101010101010101010101010101010101
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 28, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0010101010101010101010101010101010101010101010101010
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 29, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0011010101010101010101010101010101010101010101010101
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0011010101010101010101010101010101010101010101010101
../src/alup.c:1702: alup__div() 'Route 2.2'
../src/alup.c:1702: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 31, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0100101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0100101010101010101010101010101010101010101010101010
...
98%: Checks: 1877, Failures: 29, Errors: 0
../tests/check_alu.c:1475:F:Core:test_alup_div_floating:5: Assertion 'memcmp( &result, &expect, sizeof(double) ) == 0' failed
...
Compilation finished successfully.
With this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
int_t alup__div( alup_t _NUM, alup_t _VAL, void *_rem, void *_tmp )
{
	if ( alup_floating( _NUM ) || alup_floating( _VAL ) )
	{
		int_t ret;
		alup_t _DST, _SRC, _DMAN, _SMAN;
		size_t exp_len, man_len;
		ssize_t exp, dexp, sexp, dbias, sbias, dbits, sbits, bits, size;
		bool_t dneg, sneg;
		
		/* Ensure dealing with just floats, impossible for both to take _tmp
		 * given the above if statment */
		
		if ( alup_floating( _NUM ) )
		{
			_DST = _NUM;
		}
		else
		{
			bits = _NUM.upto - _NUM.from;
			size = BITS2SIZE( bits );
			alup_init_floating( _DST, _tmp, size );
			alup_mov( _DST, _NUM );
		}
		
		if ( alup_floating( _VAL ) )
		{
			_SRC = _VAL;
		}
		else
		{
			bits = _VAL.upto - _VAL.from;
			size = BITS2SIZE( bits );
			alup_init_floating( _SRC, _tmp, size );
			alup_mov( _SRC, _VAL );
		}
		
		dneg = alup_below0( _DST );
		sneg = alup_below0( _SRC );
		alub_set( _DST.data, _DST.upto - 1, dneg != sneg );
		
		dexp = alup_get_exponent( _DST );
		sexp = alup_get_exponent( _SRC );
		
		if ( !dexp || !sexp )
		{
			_NUM.upto--;
			alup_set( _NUM, 0 );
			return 0;
		}
		
		dbias = alup_get_exponent_bias( _DST );
		dexp -= dbias;
		
		sbias = alup_get_exponent_bias( _DST );
		sexp -= sbias;
				
		alup_init_mantissa( _DST, _DMAN );
		alup_init_mantissa( _SRC, _SMAN );
		
		dbits = _DMAN.upto - _DMAN.from;
		sbits = _SMAN.upto - _SMAN.from;
		bits = LOWEST( dbits, sbits );
		
		exp_len = (_DST.upto - _DMAN.upto) - 1;
		man_len = (_DMAN.upto - _DST.from);
		_SMAN.from = _SMAN.upto - EITHER( sexp >= 0 && sexp < bits, sexp, bits );
		
		alub_set( _SMAN.data, _SMAN.upto, 1 );
		_DMAN.upto = _DST.upto - 1;
		_SMAN.upto++;
		
		alup__shl( _DMAN, exp_len - 1 );
		alub_set( _DMAN.data, _DMAN.upto - 1, 1 );
		ret = alup__div_int2int( _DMAN, _SMAN, _rem );
		
		/* We mangled this so restore it now */
		alup_set_exponent( _SRC, sexp + sbias );

#if 1
		if ( ret == EOVERFLOW )
		{
			dexp--;
			//alup__shr( _DMAN, 1 );
			//alub_set( _DMAN.data, _DMAN.upto - 1, 1 );
		}
#endif
		
		exp = dexp - sexp;
		if ( exp > dbias )
		{	
			alu_puts("Route 1");
			/* Set infinity */
			_DMAN.upto = (_DST.upto - exp_len) - 1;
			alup_set( _DMAN, 0 );
			alup_set_exponent( _DST, (dbias << 1) | 1 );
		}
		else if ( exp <= (ssize_t)(_DMAN.upto - _DMAN.from) )
		{
			alub_t e = alup_end_bit( _DMAN );
			ssize_t pos = (_DMAN.upto - e.bit) - 1;
			bool_t round = 0;
			
			if ( pos >= (exp_len-1) )
			{
				alu_puts("Route 2.1");
				alup__shr( _DMAN, (exp_len - 1) );
				//alup__shr( _DMAN, ((_DMAN.upto - _DST.from) - pos) );
			}
			else
			{
				alu_puts("Route 2.2");
				alup__shr( _DMAN, (exp_len - pos) - 1 );
				if ( round )
				{
					alup_inc( _DMAN );
				}
			}
			alup_set_exponent( _DST, exp + dbias );
		}	
		else
		{
			alu_puts("Route 3");
			alup_set_exponent( _DST, exp + dbias );
		}
		
		if ( alup_floating( _NUM ) )
			return 0;
			
		return alup_mov( _NUM, _DST );
	}
	
	return alup__div_int2int( _NUM, _VAL, _rem );
}

I think it's just the normalisation stage that needs work (where I have the alu_puts() calls)
Managed to fix the mantissa, it's just the exponent that needs fixing:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
int_t alup__div( alup_t _NUM, alup_t _VAL, void *_rem, void *_tmp )
{
	if ( alup_floating( _NUM ) || alup_floating( _VAL ) )
	{
		int_t ret;
		alup_t _DST, _SRC, _DMAN, _SMAN;
		size_t exp_len, man_len;
		ssize_t exp, dexp, sexp, dbias, sbias, dbits, sbits, bits, size;
		bool_t dneg, sneg;
		
		/* Ensure dealing with just floats, impossible for both to take _tmp
		 * given the above if statment */
		
		if ( alup_floating( _NUM ) )
		{
			_DST = _NUM;
		}
		else
		{
			bits = _NUM.upto - _NUM.from;
			size = BITS2SIZE( bits );
			alup_init_floating( _DST, _tmp, size );
			alup_mov( _DST, _NUM );
		}
		
		if ( alup_floating( _VAL ) )
		{
			_SRC = _VAL;
		}
		else
		{
			bits = _VAL.upto - _VAL.from;
			size = BITS2SIZE( bits );
			alup_init_floating( _SRC, _tmp, size );
			alup_mov( _SRC, _VAL );
		}
		
		dneg = alup_below0( _DST );
		sneg = alup_below0( _SRC );
		alub_set( _DST.data, _DST.upto - 1, dneg != sneg );
		
		dexp = alup_get_exponent( _DST );
		sexp = alup_get_exponent( _SRC );
		
		if ( !dexp || !sexp )
		{
			_NUM.upto--;
			alup_set( _NUM, 0 );
			return 0;
		}
		
		dbias = alup_get_exponent_bias( _DST );
		dexp -= dbias;
		
		sbias = alup_get_exponent_bias( _DST );
		sexp -= sbias;
				
		alup_init_mantissa( _DST, _DMAN );
		alup_init_mantissa( _SRC, _SMAN );
		
		dbits = _DMAN.upto - _DMAN.from;
		sbits = _SMAN.upto - _SMAN.from;
		bits = LOWEST( dbits, sbits );
		
		exp_len = (_DST.upto - _DMAN.upto) - 1;
		man_len = (_DMAN.upto - _DST.from);
		_SMAN.from = _SMAN.upto - EITHER( sexp >= 0 && sexp < bits, sexp, bits );
		
		alub_set( _SMAN.data, _SMAN.upto, 1 );
		_DMAN.upto = _DST.upto - 1;
		_SMAN.upto++;
		
		alup__shl( _DMAN, exp_len - 1 );
		alub_set( _DMAN.data, _DMAN.upto - 1, 1 );
		ret = alup__div_int2int( _DMAN, _SMAN, _rem );
		
		/* We mangled this so restore it now */
		alup_set_exponent( _SRC, sexp + sbias );

#if 0
		if ( ret == EOVERFLOW )
		{
			dexp--;
			//alup__shr( _DMAN, 1 );
			//alub_set( _DMAN.data, _DMAN.upto - 1, 1 );
		}
#endif
		
		exp = dexp - sexp;
		if ( exp > dbias )
		{	
			alu_puts("Route 1");
			/* Set infinity */
			_DMAN.upto = (_DST.upto - exp_len) - 1;
			alup_set( _DMAN, 0 );
			alup_set_exponent( _DST, (dbias << 1) | 1 );
		}
		else if ( exp <= (ssize_t)(_DMAN.upto - _DMAN.from) )
		{
			/* Normalise */
			alub_t
				final = alup_final_one( _DMAN )
				, first = alup_first_one( _DMAN );
			ssize_t pos = (_DMAN.upto - final.bit) - 1;
			bool_t round = (first.bit - _DST.from < exp_len);
			
			if ( pos >= (exp_len-1) )
			{
				alu_puts("Route 2.1");
				alup__shr( _DMAN, (exp_len - 1) );
				//alup__shr( _DMAN, ((_DMAN.upto - _DST.from) - pos) );
			}
			else
			{
				alu_puts("Route 2.2");
				
				alup__shr( _DMAN, (exp_len - pos) - 2 );
				
				if ( round )
				{
					--exp;
					alup_inc( _DMAN );
				}
				
				alup__shr( _DMAN, 1 );
			}
			alup_set_exponent( _DST, exp + dbias );
		}	
		else
		{
			alu_puts("Route 3");
			alup__shr( _DMAN, (exp_len - 1) );
			alup_set_exponent( _DST, exp + dbias );
		}
		
		if ( alup_floating( _NUM ) )
			return 0;
			
		return alup_mov( _NUM, _DST );
	}
	
	return alup__div_int2int( _NUM, _VAL, _rem );
}
Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
make check.run
...
Running suite(s): ALU
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 7, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 0010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0000 01111111111 0010101010101010101010101010101010101010101010101011
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 9, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0001 10000000000 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 1000000000000000000000000000000000000000000000000000
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 13, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 0001010101010101010101010101010101010101010101010101
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 0001010101010101010101010101010101010101010101010101
../src/alup.c:1727: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 14, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 0010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0001 10000000000 0010101010101010101010101010101010101010101010101011
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 18, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0003 10000000010 1000000000000000000000000000000000000000000000000000
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 21, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0002 10000000001 1100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0003 10000000010 1100000000000000000000000000000000000000000000000000
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 25, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0000101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0000101010101010101010101010101010101010101010101011
../src/alup.c:1727: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 26, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0001010101010101010101010101010101010101010101010101
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0001010101010101010101010101010101010101010101010101
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 28, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0010101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0010101010101010101010101010101010101010101010101011
../src/alup.c:1727: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 29, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0011010101010101010101010101010101010101010101010101
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0011010101010101010101010101010101010101010101010101
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 31, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0100101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0002 10000000001 0100101010101010101010101010101010101010101010101011
../src/alup.c:1727: alup__div() 'Route 2.2'
../src/alup.c:1727: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 33, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 0110000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0004 10000000011 0110000000000000000000000000000000000000000000000000
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 36, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 1000000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0004 10000000011 1000000000000000000000000000000000000000000000000000
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 39, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 1010000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0004 10000000011 1010000000000000000000000000000000000000000000000000
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 42, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 1100000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0004 10000000011 1100000000000000000000000000000000000000000000000000
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 45, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0003 10000000010 1110000000000000000000000000000000000000000000000000
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0004 10000000011 1110000000000000000000000000000000000000000000000000
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 49, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0004 10000000011 0000010101010101010101010101010101010101010101010101
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0003 10000000010 0000010101010101010101010101010101010101010101010101
../src/alup.c:1727: alup__div() 'Route 2.2'
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 50, _val = 3, exp length = 11, man length = 52
../tests/check_alu.c:1465: test_alup_div_floating_fn() _EXPECT = 0 +0004 10000000011 0000101010101010101010101010101010101010101010101011
../tests/check_alu.c:1466: test_alup_div_floating_fn() _RESULT = 0 +0003 10000000010 0000101010101010101010101010101010101010101010101011
../src/alup.c:1727: alup__div() 'Route 2.2'
...
../tests/check_alu.c:1456: test_alup_div_floating_fn() _num = 52, _val = 3, exp length = 11, man length = 52
...
98%: Checks: 1877, Failures: 19, Errors: 0
...
About to start work so can't respond to any msgs but I mamged to fix the division algorithm, code is already uploaded to my github project so feel free test various things since I still need to expand the types of tests
Topic archived. No new replies allowed.