Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. int getMax(int a, int b) {
  2. int c = a - b;
  3. int k = (c >> 31) & 0x1;
  4. int max = a - k * c;
  5. return max;
  6. }
  7.  
  8. int getMax(int a, int b) {
  9. int c = a - b;
  10. int k = (c >> 31) & 0x1;
  11. int max = a - k * c;
  12. return max;
  13. }
  14.  
  15. int k = (c >> 31) & 0x1;
  16.  
  17. int max = a - k * c;
  18.  
  19. a - k * c = a - (a - b) = a - a + b = b
  20.  
  21. a - k * c = a - 0 = a
  22.  
  23. r = x ^ ((x ^ y) & -(x < y)); // max(x, y)
  24.  
  25. r = x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))); // max(x, y)
  26.  
  27. (sqrt( a*a + b*b - 2*a*b ) + a + b) / 2
  28.  
  29. #include <math.h>
  30.  
  31. int Max(int x, int y)
  32. {
  33. return (float)(x + y) / 2.0 + abs((float)(x - y) / 2);
  34. }
  35.  
  36. int Min(int x, int y)
  37. {
  38. return (float)(x + y) / 2.0 - abs((float)(x - y) / 2);
  39. }
  40.  
  41. int max(int i, int j) {
  42. int m = ((i-j) >> 31);
  43. return (m & j) + ((~m) & i);
  44. }
  45.  
  46. max (a, b) = new[] { a, b } [((a - b) >> 31) & 1]
  47.  
  48. #define BITS (CHAR_BIT * sizeof(int) - 1)
  49.  
  50. int findmax(int a, int b) {
  51. int rets[] = {a, b};
  52. return rets[unsigned(a-b)>>BITS];
  53. }
  54.  
  55. int getMax(int a, int b){
  56. return (a+b+((a-b)>>sizeof(int)*8-1|1)*(a-b))/2;
  57. }
  58.  
  59. max
  60. = ( max + max ) / 2
  61. = ( max + (min+differenceOfMaxMin) ) / 2
  62. = ( max + min + differenceOfMaxMin ) / 2
  63. = ( max + min + | max - min | ) ) / 2
  64.  
  65. getMax(a, b)
  66. = ( a + b + absolute(a - b) ) / 2
  67.  
  68. absolute(a)
  69. = a [if 'a' is positive] or -a [if 'a' is negative]
  70. = a * ( 1 [if 'a' is positive] or -1 [if 'a' is negative] )
  71.  
  72. absolute(a)
  73. = a * ( 1 [if 'a' is positive] or -1 [if 'a' is negative] )
  74. = a * ( ( a >> (numberOfBitsInInteger-1) ) | 1 )
  75. = a * ( ( a >> ((numberOfBytesInInteger*bitsInOneByte) - 1) ) | 1 )
  76. = a * ( ( a >> ((sizeOf(int)*8) - 1) ) | 1 )
  77.  
  78. getMax(a, b)
  79. = ( a + b + absolute(a - b) ) / 2
  80. = ( a + b + ((a-b) * ( ( (a-b) >> ((sizeOf(int)*8) - 1) ) | 1 )) ) / 2
  81.  
  82. {
  83. int[] arr;
  84. arr = new int[3];
  85. arr[0] = b;
  86. arr[1] = a;
  87. arr[2] = a;
  88. return arr[Math.Sign(a - b) + 1];
  89.  
  90. }
  91.  
  92. double findmax(double a, double b)
  93. {
  94. //find the difference of the two numbers
  95. double diff=a-b;
  96. double temp_diff=diff;
  97. int int_diff=temp_diff;
  98. /*
  99. For the floating point numbers the difference contains decimal
  100. values (for example 0.0009, 2.63 etc.) if the left side of '.' contains 0 then we need
  101. to get a non-zero number on the left side of '.'
  102. */
  103. while ( (!(int_diff|0)) && ((temp_diff-int_diff)||(0.0)) )
  104. {
  105. temp_diff = temp_diff * 10;
  106. int_diff = temp_diff;
  107. }
  108. /*
  109. shift the sign bit of variable 'int_diff' to the LSB position and find if it is
  110. 1(difference is -ve) or 0(difference is +ve) , then multiply it with the difference of
  111. the two numbers (variable 'diff') then subtract it with the variable a.
  112. */
  113. return a- (diff * ( int_diff >> (sizeof(int) * 8 - 1 ) & 1 ));
  114. }
  115.  
  116. #include<stdio.h>
  117. main()
  118. {
  119. int num1,num2,diff;
  120. printf("Enter number 1 : ");
  121. scanf("%d",&num1);
  122. printf("Enter number 2 : ");
  123. scanf("%d",&num2);
  124. diff=num1-num2;
  125. num1=abs(diff);
  126. num2=num1+diff;
  127. if(num1==num2)
  128. printf("Both number are equaln");
  129. else if(num2==0)
  130. printf("Num2 > Num1n");
  131. else
  132. printf("Num1 > Num2n");
  133. }
  134.  
  135. public static int Min(int a, int b)
  136. {
  137. int dif = (int)(((uint)(a - b)) >> 31);
  138. return a * dif + b * (1 - dif);
  139. }
  140.  
  141. return (a>=b)?b:a;
  142.  
  143. c=|a/b|+1;
  144. d=(c-1)/b;
  145. smallest number= a - d*(a-b);
  146.  
  147. int a=151;
  148. int b=121;
  149. int k=Math.abs(a-b);
  150. int j= a+b;
  151. double k1=(double)(k);
  152. double j1= (double) (j);
  153. double c=Math.ceil(k1/2) + Math.floor(j1/2);
  154. int c1= (int) (c);
  155. System.out.println(" Max value = " + c1);
  156.  
  157. int max=(a>b)*a+(a<=b)*b;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement