Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* The ipow() function is a function I wrote to return the power of an integer without needing a cast
- * The buf_update() function puts the generated digits into a buffer and keeps track of the pointers
- * for said buffer. Getting the input from the terminal and getting the values back from the buffer
- * are handled with separate functions that don't have much to do with this code and that I know work.
- * The functions that have declarations here are the only ones this function depends on */
- void connegbase(int n, int r)
- {
- /*
- * Gives 1 1 8 70 1 for digit values which is obviously wrong
- * for -124 converting to base -10
- */
- /* Takes the number to be converted n, and the base to convert to r */
- static int e = 0, e_flg = false;
- int m;
- /* These functions are not the problem */
- int ipow(int n, int e);
- void buf_update(int n);
- /* Find the minimum power of r whose absolute value is greater than |n| */
- while ( !e_flg &&
- abs(ipow(r, e++)) < abs(n)) {
- ;
- }
- e_flg = true; /* So above loop doesn't execute again */
- /* Find minimum multiplicator of |r^e| that is > |n| */
- for (m = 0; m * abs(ipow(r, e)) < abs(n); ++m) {
- ;
- }
- buf_update(m);
- if (e && n) {
- /* | m * r^e - |n| | passed as n */
- connegbase(abs(m * ipow(r, --e)) - abs(n), r);
- }
- e_flg = false; /* Reset for next invocation */
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement