To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit d3c28b03 authored by John Zhang's avatar John Zhang
Browse files

float bitcasting using C function

parent e8c1c53e
......@@ -9,7 +9,7 @@ RPYC_DIR = ../../c
RPYC_SRC_DIR = $(RPYC_DIR)/src
PYPY_MOD_DIR = ../../../../pypy/module
CC = cc
OBJS = dtoa.o utils.o errno.o tscmp.o linux_debug.o fakestack.o
OBJS = dtoa.o utils.o errno.o tscmp.o linux_debug.o fakestack.o bitcastfloat.o
FLAGS = -D__MU__
dtoa.o: $(RPYC_SRC_DIR)/dtoa.c $(RPYC_SRC_DIR)/dtoa.h
......@@ -30,6 +30,9 @@ linux_debug.o: src/linux_debug.c
fakestack.o: src/fakestack.c
$(CC) -fPIC $(FLAGS) -c -o $@ $<
bitcastfloat.o: src/bitcastfloat.c
$(CC) -fPIC $(FLAGS) -c -o $@ $<
librpyc.so: $(OBJS)
$(CC) -shared -o $@ $(OBJS)
rm $(OBJS)
......
#include <string.h>
#include <assert.h>
float pypy__uint2singlefloat(unsigned int x) {
float ff;
assert(sizeof(float) == 4 && sizeof(unsigned int) == 4);
memcpy(&ff, &x, 4);
return ff;
}
unsigned int pypy__singlefloat2uint(float x) {
unsigned int ii;
assert(sizeof(float) == 4 && sizeof(unsigned int) == 4);
memcpy(&ii, &x, 4);
return ii;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment