This file contains 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
__forceinline double chebyshev_ryg(int n, double x) | |
{ | |
if (n == 0) return 1.0; | |
if (n == 1) return x; | |
double t = x, t1 = 1, t2; | |
// if you don't use a for here, the vc++ loop optimizer doesn't get it! | |
for (int i=1; i<n; i++) { | |
t2 = t1; | |
t1 = t; |
This file contains 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
__forceinline double chebyshev_ryg(int n, double x) | |
{ | |
if (n == 0) return 1.0; | |
if (n == 1) return x; | |
double t = x, t1 = 1, t2; | |
x += x; | |
for (int i=1; i<n; i++) { | |
t2 = t1; | |
t1 = t; |
This file contains 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
ulong icbrt64(ulong x) { | |
int s; | |
ulong y, b, bs; | |
s = 30; | |
y = 0; | |
while (s >= 0) { | |
y += y; | |
b = 3*y*(y * 1) + 1; | |
bs = b << s; |
This file contains 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> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
#include <time.h> | |
// ---- platform specific part | |
enum { | |
CURSOR_LEFT = 256, |
This file contains 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 <windows.h> | |
#include <D3D10.h> | |
#include <D3DX10.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdarg.h> | |
#include <algorithm> | |
// "Does your GPU have pixel alignment requirements for quads?" tester | |
// Win32 only, D3D10+ only because it's a quick hack. |
This file contains 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
ErrorCode Read(BufferedStream *s, void *buffer, size_t numBytes) | |
{ | |
U8 *dest = (U8 *)buffer; | |
while (numBytes) { | |
if (s->cursor == s->end) | |
s->Refill(s); | |
size_t count = min(numBytes, (size_t)(s->end - s->cursor)); | |
memcpy(dest, s->cursor, count); | |
dest += count; | |
s->cursor += count; |
This file contains 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
0000: 0 = a xor a | |
0001: a and b | |
0010: a and (not b) = a andc b | |
0011: b = b and b | |
0100: (not a) and b = b andc a | |
0101: a = a and a | |
0110: a xor b | |
0111: a or b | |
1000: (not a) and (not b) = not (a or b) = a nor b | |
1001: (not a) xor b = a xnor b |
This file contains 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
static inline U32 ppcmask(U32 mb, U32 me) | |
{ | |
U32 maskmb = ~0u >> mb; | |
U32 maskme = ~0u << (31 - me); | |
return (mb <= me) ? maskmb & maskme : maskmb | maskme; | |
} | |
static inline U32 rotl32(U32 x, U32 amount) | |
{ | |
return (x << amount) | (x >> ((32 - amount) & 31)); |
This file contains 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
bool contains(const T& value) | |
{ | |
#if 0 // variant 0 | |
return std::binary_search(values.begin(), values.end(), value); | |
#elif 0 // variant 1 | |
size_t l = 0, r = values.size(); | |
while (l < r) { | |
size_t x = (l + r) >> 1; | |
if (values[x] < value) | |
l = x + 1; |
This file contains 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
This program estimates a rotation under constraints that are naturally stated in angles. | |
The original version works directly on Euler angles: first an initial solution is | |
determined using an iterative algorithm, then positions of other local optima are | |
determined (this is the part that works in angles), then the candidate solutions are | |
evaluated and passed through the iterative algorithm again to polish the results. Here's | |
the result of solving a few instances of the problem. Note that the initial solution is | |
always found as one of the valid solutions (as it should be), but the constrained | |
minimization part sometimes produces significant amount of error that requires a lot of | |
extra iterations to correct: |
OlderNewer