Ticket #1951 (new enhancement) — at Version 4

Opened 13 years ago

Last modified 11 years ago

Simplify

Reported by: pavlinux Owned by:
Priority: major Milestone:
Component: mc-core Version: master
Keywords: Cc:
Blocked By: Blocking:
Branch state: no branch Votes for changeset:

Description (last modified by styx) (diff)

(x + 1) * 2 = ++x << 1

Change History

comment:1 Changed 13 years ago by pavlinux

Code for test

#include <stdio.h>

int main(void) {

        int sp = 0;
        int dp = 0;

       while ( sp < 0xFF /* just limit */ ) {

                sp = (++sp << 1);
                dp = 2 * ( dp + 1 );

                printf("%d = %d\n", sp, dp);
        }
 return 0;
}

comment:2 Changed 13 years ago by pavlinux

Sorry bug. =)

Changed 13 years ago by pavlinux

comment:3 Changed 13 years ago by pavlinux

May be this

#include <stdio.h>
#define LIMIT 0x20
int main() {

int sp = 0;
int dp = 0;
int i = 0;

while ( (2*dp) <= LIMIT ) {

printf("%ld\n", 2*dp);
dp++;

}

while ( sp <= LIMIT ) {

printf("%ld\n", sp);
sp = 2 * ++i;

}

return 0;

}

comment:4 Changed 13 years ago by styx

  • Description modified (diff)

In you code variables are named not well. 'i' is now equal to 'backspaces' an 'backspaces' became to be equal to 2*old_backspaces. Yes, the result is the same, but the logic is changed.

Note: See TracTickets for help on using tickets.