-
-
Save nonchip/b7d325a47f5446c82c79d4ceff008553 to your computer and use it in GitHub Desktop.
divides stuff by 12 to test other stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void main(void){ | |
for(int i=-13;i<=13;i++){ | |
int iresult=i/12; | |
float fresult=((float)i)/12.0f; | |
printf("%d\t%d\t%d\t%f\n",i,iresult,((int)fresult),fresult); | |
} | |
} | |
/* | |
-13 -1 -1 -1.083333 | |
-12 -1 -1 -1.000000 | |
-11 0 0 -0.916667 | |
-10 0 0 -0.833333 | |
-9 0 0 -0.750000 | |
-8 0 0 -0.666667 | |
-7 0 0 -0.583333 | |
-6 0 0 -0.500000 | |
-5 0 0 -0.416667 | |
-4 0 0 -0.333333 | |
-3 0 0 -0.250000 | |
-2 0 0 -0.166667 | |
-1 0 0 -0.083333 | |
0 0 0 0.000000 | |
1 0 0 0.083333 | |
2 0 0 0.166667 | |
3 0 0 0.250000 | |
4 0 0 0.333333 | |
5 0 0 0.416667 | |
6 0 0 0.500000 | |
7 0 0 0.583333 | |
8 0 0 0.666667 | |
9 0 0 0.750000 | |
10 0 0 0.833333 | |
11 0 0 0.916667 | |
12 1 1 1.000000 | |
13 1 1 1.083333 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local math=require'math' | |
local function intdiv(a, b) -- Lua actually doesn't do integers until version 5.3 (which you don't wanna use because LuaJIT), so truncating here | |
q = a/b | |
return (q > 0) and math.floor(q) or math.ceil(q) | |
end | |
for i=-13,13 do | |
iresult=intdiv(i,12) | |
fresult=i/12.0 | |
print(("%d\t%d\t%d\t%f"):format(i,iresult,intdiv(fresult,1),fresult)) | |
end | |
--[[ | |
-13 -1 -1 -1.083333 | |
-12 -1 -1 -1.000000 | |
-11 0 0 -0.916667 | |
-10 0 0 -0.833333 | |
-9 0 0 -0.750000 | |
-8 0 0 -0.666667 | |
-7 0 0 -0.583333 | |
-6 0 0 -0.500000 | |
-5 0 0 -0.416667 | |
-4 0 0 -0.333333 | |
-3 0 0 -0.250000 | |
-2 0 0 -0.166667 | |
-1 0 0 -0.083333 | |
0 0 0 0.000000 | |
1 0 0 0.083333 | |
2 0 0 0.166667 | |
3 0 0 0.250000 | |
4 0 0 0.333333 | |
5 0 0 0.416667 | |
6 0 0 0.500000 | |
7 0 0 0.583333 | |
8 0 0 0.666667 | |
9 0 0 0.750000 | |
10 0 0 0.833333 | |
11 0 0 0.916667 | |
12 1 1 1.000000 | |
13 1 1 1.083333 | |
]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(-13,14): | |
iresult = i//12 | |
fresult = i/12 | |
print('%d\t%d\t%d\t%f' % (i, iresult, int(fresult), fresult)) | |
''' | |
-13 -2 -1 -1.083333 | |
-12 -1 -1 -1.000000 | |
-11 -1 0 -0.916667 | |
-10 -1 0 -0.833333 | |
-9 -1 0 -0.750000 | |
-8 -1 0 -0.666667 | |
-7 -1 0 -0.583333 | |
-6 -1 0 -0.500000 | |
-5 -1 0 -0.416667 | |
-4 -1 0 -0.333333 | |
-3 -1 0 -0.250000 | |
-2 -1 0 -0.166667 | |
-1 -1 0 -0.083333 | |
0 0 0 0.000000 | |
1 0 0 0.083333 | |
2 0 0 0.166667 | |
3 0 0 0.250000 | |
4 0 0 0.333333 | |
5 0 0 0.416667 | |
6 0 0 0.500000 | |
7 0 0 0.583333 | |
8 0 0 0.666667 | |
9 0 0 0.750000 | |
10 0 0 0.833333 | |
11 0 0 0.916667 | |
12 1 1 1.000000 | |
13 1 1 1.083333 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment