pouët.net

Random line of code thread

category: code [glöplog]
How (for concreteness, 32 bits):
(0 <= x)? x:-x
-x = ~(x - 1)
If x < 0 then -x = ~(x - (x SHL 31)) because, in 2's complement, x's bit 31 = 1
If 0 <= x then x = (x - (x SHL 31)) because then, x's bit 31 = 0
Now, ~y = (0xffffffff)^y. So,
if x < 0 then -x = (x SAR 31)^(x - (x SHL 31)) because then x SAR 31 = 0xffffffff
If 0 <= x then x = (x SAR 31)^(x - (x SHL 31)) because then x SAR 31 = 0 and 0^y = y.
Hence, both cases can be expressed by one formula: (x SAR 31)^(x - (x SHL 31)).
added on the 2013-01-24 21:32:57 by Kais Kais
Code:Vector3 rowanpos = m_v2 + (m_v1 - m_v2).norm() * m_berryDistance;

added on the 2013-03-09 22:48:41 by Preacher Preacher
Code:setne dl
Code: #include <stdio.h> void main() { int n; n=666; // the C preprocessor is your friend, my friend... \ n=42; printf("n=%d\n",n); }
added on the 2013-03-10 01:46:55 by blala blala
Code:nvhost_pushbuf_push(pb, NVHOST_OPCODE_INCR(0x121, 0x03)); nvhost_pushbuf_relocate(pb, gr3d->attributes, 0x60, 0); nvhost_pushbuf_push(pb, 0xdeadbeef); nvhost_pushbuf_push(pb, 0xec000000); nvhost_pushbuf_push(pb, 0x00200000);
added on the 2013-03-11 12:13:25 by kusma kusma
d=22,D=d*d;A=300;M=Math;t=K=0;f='function P(v0,v1,v2,v3){Z=0;';for(i=0;i<4;i++)f+='if(V[B+v'+i+'].r<0)Z|='+(1<<i)+';';for(q in U=[51278,40221,55500,35292,58923,52810,59722,60745,59465,31544]){u=U[q];F=[];l=u;for(i=0;i<3;i++){l>>=4;F.push('{G:(C=V[v'+(l&3)+'+B]).G+(Q=-C.r/((Y=V[v'+(l>>2&3)+'+B]).r-C.r))*(Y.G-C.G),H:C.H+Q*(Y.H-C.H)}')}f+='if(Z=='+(u&15)+'||Z=='+(~u&15)+')T.push(['+F.join()+']);'}f+='}';eval(f);V=[];for(i=0;i<d*D;i++)V[i]=({x:((i/D)-(d-1)/2)/d,y:-((i%d)-(d-1)/2)/d,z:-(((i/d)%d)-(d-1)/2)/d});setInterval(function(){t++;X=[];for(i=0;i<24;i++)X[i]=M.sin(((t/10)+(i*33%13))/(0.5+((i*91%12)*0.1)))*0.30;for(i in V){V[i].G=(V[i].x/(V[i].z+0.8))*A+A;V[i].H=(V[i].y/(V[i].z+0.8))*A+A;v=0;for(j=0;j<24;j+=3){x=V[i].x+X[j];y=V[i].y+X[j+1];z=V[i].z+X[j+2];v+=1/(x*x+y*y+z*z)}V[i].r=v/16-6}T=[];for(B=0;B<M.pow(d-1,3);B++){E=D+d;W=d+1;R=E+1;P(0,W,d,E);P(0,W,R,E);P(0,D,R,E);P(0,R,1,W);P(0,R,1,D);P(D+1,R,1,D)}c.width=c.height=600;for(i in T){S=T[i];a.beginPath();for(j in S)a.lineTo(S[j].G,S[j].H);a.stroke()}},20)
added on the 2013-03-12 14:11:56 by Inopia Inopia
Code: #
added on the 2013-03-12 20:42:12 by bull bull
Code:loop fat
Code:c = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!?.,"[i];

Living on the edge of C..
added on the 2013-03-18 22:51:43 by Tjoppen Tjoppen
Code:main = putStrLn $ a ++ show a where a = "main = putStrLn $ a ++ show a where a = "
added on the 2013-03-19 22:39:44 by FreeFull FreeFull
From http://hackers-delight.org.ua/065.htm:

Code: Divide by 3 li M,0x55555556 Load magic number, (2**32+2)/3. mulhs q,M,n q = floor(M*n/2**32). shri t,n,31 Add 1 to q if add q,q,t n is negative. muli t,q,3 Compute remainder from sub r,n,t r = n - q*3.
added on the 2013-03-21 16:19:11 by すすれ すすれ
Code: #!/opt/wmi/bin/perl # griffiol - 23.03.2013 use strict; use warnings; if ($#ARGV+1 != 1) { print "Usage: $0 'n1 n2 n3 n4 n5'\n"; exit 1 } my $CHECK = "OK"; my $CRONTAB = $ARGV[0]; chomp($CRONTAB); my @ELEM = split(' ',$ARGV[0]); if ($#ELEM+1 != 5) { print "a crontab schedule must have 5 elements separated by spaces or tabs\n"; exit 2; } foreach my $CRON_ENTRY (@ELEM) { if ($CRON_ENTRY !~ /^(\*|[0-9]{1,2}|[0-9]{1,2}(,[0-9]{1,2})+|[0-9]{1,2}(-[0-9]{1,2})+)$/) { $CHECK = "FAIL"; } } if ($CHECK eq "OK") { print "$CHECK\n"; exit 0 } else { print "$CHECK\n"; exit 3 }
added on the 2013-03-21 17:56:09 by bull bull
Code: move.l #'PROP',d1 move.l #'HETS',d2 move.l #' AG-',d3 move.l #'-WE ',d4 move.l #'FUCK',d5 move.l #' CRU',d6 move.l #'SH--',d7
added on the 2013-09-25 07:15:48 by StingRay StingRay
Code:mov [bp+4],cx
Code: sub.l #$30061973,(a0)+


Always interesting which secrets a single line of code can reveal. :)
added on the 2013-09-26 18:49:15 by StingRay StingRay
int 13
added on the 2013-09-27 07:09:10 by trixter trixter
Code: } } } } } } } } }
added on the 2013-09-30 12:27:30 by cupe cupe
code tag, you had one job.
added on the 2013-09-30 13:13:00 by cupe cupe
Code: private IStuffType _stuff; [CanBeNull] public IStuffType Stuff { get { return _stuff; } set { if (_stuff!= null) { _stuff.ShitHappened -= StuffOnShitHappened; } _stuff= value; if (_stuff!= null) { _stuff.ShitHappened += StuffOnShitHappened; } RefreshShit(); } }


All day everyday..
added on the 2013-09-30 16:24:42 by Orace Orace
Code:adc al,byte[ds:di+bx+1]
Code: dbf d0,scheisse
added on the 2013-10-22 11:00:48 by StingRay StingRay
Code:eval(atob(location.href.match(/([^\/]*)\.htm/i)[1]))
added on the 2013-10-22 18:50:54 by Suborg Suborg
Code:out 42h,al
added on the 2013-10-23 06:58:22 by trixter trixter
29560 gosub 18010
10 PRINT CHR$(205.5 RND(1)); : GOTO 10
added on the 2013-10-23 12:08:32 by w00t! w00t!

login