Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int getMax(int a, int b) {
- int c = a - b;
- int k = (c >> 31) & 0x1;
- int max = a - k * c;
- return max;
- }
- int getMax(int a, int b) {
- int c = a - b;
- int k = (c >> 31) & 0x1;
- int max = a - k * c;
- return max;
- }
- int k = (c >> 31) & 0x1;
- int max = a - k * c;
- a - k * c = a - (a - b) = a - a + b = b
- a - k * c = a - 0 = a
- r = x ^ ((x ^ y) & -(x < y)); // max(x, y)
- r = x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))); // max(x, y)
- (sqrt( a*a + b*b - 2*a*b ) + a + b) / 2
- #include <math.h>
- int Max(int x, int y)
- {
- return (float)(x + y) / 2.0 + abs((float)(x - y) / 2);
- }
- int Min(int x, int y)
- {
- return (float)(x + y) / 2.0 - abs((float)(x - y) / 2);
- }
- int max(int i, int j) {
- int m = ((i-j) >> 31);
- return (m & j) + ((~m) & i);
- }
- max (a, b) = new[] { a, b } [((a - b) >> 31) & 1]
- #define BITS (CHAR_BIT * sizeof(int) - 1)
- int findmax(int a, int b) {
- int rets[] = {a, b};
- return rets[unsigned(a-b)>>BITS];
- }
- int getMax(int a, int b){
- return (a+b+((a-b)>>sizeof(int)*8-1|1)*(a-b))/2;
- }
- max
- = ( max + max ) / 2
- = ( max + (min+differenceOfMaxMin) ) / 2
- = ( max + min + differenceOfMaxMin ) / 2
- = ( max + min + | max - min | ) ) / 2
- getMax(a, b)
- = ( a + b + absolute(a - b) ) / 2
- absolute(a)
- = a [if 'a' is positive] or -a [if 'a' is negative]
- = a * ( 1 [if 'a' is positive] or -1 [if 'a' is negative] )
- absolute(a)
- = a * ( 1 [if 'a' is positive] or -1 [if 'a' is negative] )
- = a * ( ( a >> (numberOfBitsInInteger-1) ) | 1 )
- = a * ( ( a >> ((numberOfBytesInInteger*bitsInOneByte) - 1) ) | 1 )
- = a * ( ( a >> ((sizeOf(int)*8) - 1) ) | 1 )
- getMax(a, b)
- = ( a + b + absolute(a - b) ) / 2
- = ( a + b + ((a-b) * ( ( (a-b) >> ((sizeOf(int)*8) - 1) ) | 1 )) ) / 2
- {
- int[] arr;
- arr = new int[3];
- arr[0] = b;
- arr[1] = a;
- arr[2] = a;
- return arr[Math.Sign(a - b) + 1];
- }
- double findmax(double a, double b)
- {
- //find the difference of the two numbers
- double diff=a-b;
- double temp_diff=diff;
- int int_diff=temp_diff;
- /*
- For the floating point numbers the difference contains decimal
- values (for example 0.0009, 2.63 etc.) if the left side of '.' contains 0 then we need
- to get a non-zero number on the left side of '.'
- */
- while ( (!(int_diff|0)) && ((temp_diff-int_diff)||(0.0)) )
- {
- temp_diff = temp_diff * 10;
- int_diff = temp_diff;
- }
- /*
- shift the sign bit of variable 'int_diff' to the LSB position and find if it is
- 1(difference is -ve) or 0(difference is +ve) , then multiply it with the difference of
- the two numbers (variable 'diff') then subtract it with the variable a.
- */
- return a- (diff * ( int_diff >> (sizeof(int) * 8 - 1 ) & 1 ));
- }
- #include<stdio.h>
- main()
- {
- int num1,num2,diff;
- printf("Enter number 1 : ");
- scanf("%d",&num1);
- printf("Enter number 2 : ");
- scanf("%d",&num2);
- diff=num1-num2;
- num1=abs(diff);
- num2=num1+diff;
- if(num1==num2)
- printf("Both number are equaln");
- else if(num2==0)
- printf("Num2 > Num1n");
- else
- printf("Num1 > Num2n");
- }
- public static int Min(int a, int b)
- {
- int dif = (int)(((uint)(a - b)) >> 31);
- return a * dif + b * (1 - dif);
- }
- return (a>=b)?b:a;
- c=|a/b|+1;
- d=(c-1)/b;
- smallest number= a - d*(a-b);
- int a=151;
- int b=121;
- int k=Math.abs(a-b);
- int j= a+b;
- double k1=(double)(k);
- double j1= (double) (j);
- double c=Math.ceil(k1/2) + Math.floor(j1/2);
- int c1= (int) (c);
- System.out.println(" Max value = " + c1);
- int max=(a>b)*a+(a<=b)*b;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement