高洛峰2017-04-17 10:58:54
最神奇的代码莫过于 Quake III 中不可思议的求解平方根实现方法,尤其是神奇的常量0x5f3759df
float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &y; // evil floating point bit level hacking i = 0x5f3759df - ( i >> 1 ); // what the fuck? y = * ( float * ) &i; y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed #ifndef Q3_VM #ifdef __linux__ assert( !isnan(y) ); // bk010122 - FPE? #endif #endif return y; }
还有这句比较好玩的:
rm -rf /usr /lib/nvidia-current/xorg/xorg
源自 https://github.com/MrMEEE/bumblebee/c...
黄舟2017-04-17 10:58:54
try { if(you.believe(it) || !you.believe(it) ){ I.believe(it); } }catch(Exception ex){ throw new Exception ("It's a miracle!"); }finally{ it.justHappened(); }
阿神2017-04-17 10:58:54
好吧,应该是这段,2011最佳代码Scala版
def believe(x: Any) = x match { case b: Boolean => "I believe." case _ => "It's miracle!" }
伊谢尔伦2017-04-17 10:58:54
qsort [] = []
qsort (x:xs) = qsort [a|a<-xs, a<x] ++ [x] ++ qsort [a|a<-xs, a>=x]
伊谢尔伦2017-04-17 10:58:54
自己写的
lazy val fibs: Stream[Int] = 1 #:: 1 #:: (fibs zip fibs.tail).map(x => x._1 + x._2)
用Haskell更漂亮