Skip to content

Instantly share code, notes, and snippets.

@denysvitali
Created April 3, 2019 07:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save denysvitali/47472aeef41db77a18130cc52470fc83 to your computer and use it in GitHub Desktop.
import sys
import numpy as np
def clamp_py(my_value, min_value, max_value):
return min(max(my_value, min_value), max_value)
vec3 = [0.0, -1.0, 0.0]
x = round(clamp_py(0.0, -1, 1) * 511.0)
y = round(clamp_py(-1.0, -1, 1) * 511.0)
z = round(clamp_py(0.0, -1, 1) * 511.0)
w = round(clamp_py(0.0, -1, 1) * 1.0)
print(sys.getsizeof(x))
print(type(x))
def tainting_type(f):
def foo(x):
x = np.array(x, dtype=f)
return x.astype(f, casting='no')
return foo
uint32_t = tainting_type(np.uint32)
int32_t = tainting_type(np.int32)
packed = 0
print(x, y, z, w)
packed += (uint32_t(x) & 0x3FF) << 20
packed += (uint32_t(y) & 0x3FF) << 10
packed += (uint32_t(z) & 0x3FF) << 2
packed += (uint32_t(w) & 0x02)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment