Fix vnode creation
This commit is contained in:
		
							parent
							
								
									0cf27783ea
								
							
						
					
					
						commit
						091c9c011e
					
				
							
								
								
									
										37
									
								
								src/vnode.c
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								src/vnode.c
									
									
									
									
									
								
							@ -5,6 +5,16 @@
 | 
			
		||||
#include "__internal/vnode.h"
 | 
			
		||||
#include "../include/string.h"
 | 
			
		||||
 | 
			
		||||
static vtype internal_round(u64_t* x, ldbl_t v) {
 | 
			
		||||
    if (v > 0) {
 | 
			
		||||
        *x = (u64_t)(v + 0.5);
 | 
			
		||||
        return VTYPE_UINT64;
 | 
			
		||||
    } else {
 | 
			
		||||
        *x = (s64_t)(v - 0.5);
 | 
			
		||||
        return VTYPE_INT64;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*#####################################################################################################################*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -12,25 +22,28 @@ static vnode_t create_value(vtype xt, const void* v, vtype t) {
 | 
			
		||||
    var_t _;
 | 
			
		||||
 | 
			
		||||
    if (t == VTYPE_FLOAT)  {
 | 
			
		||||
        _.u64 = (s64_t)roundf(*(fl_t*)v);
 | 
			
		||||
        t     = VTYPE_INT64;
 | 
			
		||||
        t = internal_round(&_.u64, *(fl_t*)v);
 | 
			
		||||
    } else if (t == VTYPE_DOUBLE) {
 | 
			
		||||
        _.u64 = (s64_t)round (*(dbl_t*)v);
 | 
			
		||||
        t     = VTYPE_INT64;
 | 
			
		||||
    } else {
 | 
			
		||||
        _.u64 = (s64_t)roundl(*(ldbl_t*)v);
 | 
			
		||||
        t     = VTYPE_INT64;
 | 
			
		||||
        t = internal_round(&_.u64, *(dbl_t*)v);
 | 
			
		||||
    } else if (t == VTYPE_LDOUBLE) {
 | 
			
		||||
        t = internal_round(&_.u64, *(ldbl_t*)v);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (sizeof(void*) == 8) {
 | 
			
		||||
        if        (t == VTYPE_UINT8  || t == VTYPE_INT8  || t == VTYPE_BOOLEAN ) {
 | 
			
		||||
        if        (t == VTYPE_UINT8  || t == VTYPE_BOOLEAN ) {
 | 
			
		||||
            _.u64 = *(u8_t*)v;
 | 
			
		||||
        } else if (t == VTYPE_UINT16 || t == VTYPE_INT16) {
 | 
			
		||||
        } else if (t == VTYPE_UINT16) {
 | 
			
		||||
            _.u64 = *(u16_t*)v;
 | 
			
		||||
        } else if (t == VTYPE_UINT32 || t == VTYPE_INT32 || (sizeof(void*) == 4 && t == VTYPE_POINTER)) {
 | 
			
		||||
        } else if (t == VTYPE_UINT32 || (sizeof(void*) == 4 && t == VTYPE_POINTER)) {
 | 
			
		||||
            _.u64 = *(u32_t*)v;
 | 
			
		||||
        } else if (t == VTYPE_UINT64 || t == VTYPE_INT64 || (sizeof(void*) == 8 && t == VTYPE_POINTER)) {
 | 
			
		||||
            _.u64 = *(u64_t*)v;
 | 
			
		||||
        } else if (t == VTYPE_INT8) {
 | 
			
		||||
            _.u64 = *(s8_t*)v;
 | 
			
		||||
        } else if (t == VTYPE_INT16) {
 | 
			
		||||
            _.u64 = *(s16_t*)v;
 | 
			
		||||
        } else if (t == VTYPE_INT32) {
 | 
			
		||||
            _.u64 = *(s32_t*)v;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (is_big_endian) {
 | 
			
		||||
@ -105,7 +118,7 @@ static vnode_t create_float(vtype xt, const void* v, vtype t) {
 | 
			
		||||
            _.ptr = memndup(&_.f, sizeof(_.f));
 | 
			
		||||
        }
 | 
			
		||||
    } else if (xt == VTYPE_DOUBLE) {
 | 
			
		||||
        _.f = _.d;
 | 
			
		||||
        _.d = _.ld;
 | 
			
		||||
        if (!is_permissible(dbl_t)) {
 | 
			
		||||
            _.ptr = memndup(&_.d, sizeof(_.d));
 | 
			
		||||
        }
 | 
			
		||||
@ -267,7 +280,7 @@ vnode_t libcdsb_vnode_create_target(vtype xt, const void* v, vtype t) {
 | 
			
		||||
 | 
			
		||||
        if (xt <= VTYPE_INT64)
 | 
			
		||||
            return create_value(xt, v, t);
 | 
			
		||||
        return create_value(xt, v, t);
 | 
			
		||||
        return create_float(xt, v, t);
 | 
			
		||||
    } else if (t == VTYPE_POINTER && (t = xt) > VTYPE_STRING) {
 | 
			
		||||
        v = *(void**)v;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,8 @@ static ldbl_t normalize_value(const void* v, vtype t) {
 | 
			
		||||
    } else return abs(*(ldbl_t*)v) <= LDBL_EPSILON ? 0 : *(ldbl_t*)v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*#####################################################################################################################*/
 | 
			
		||||
 | 
			
		||||
int libcdsb_vtype_compare_values(const void* s0, vtype t0, const void* s1, vtype t1) {
 | 
			
		||||
    if (t0 == t1) return libcdsb_vtype_compare_values_eq(s0, s1, t0);
 | 
			
		||||
 | 
			
		||||
@ -45,8 +47,6 @@ int libcdsb_vtype_compare_values(const void* s0, vtype t0, const void* s1, vtype
 | 
			
		||||
    return t0 - t1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*#####################################################################################################################*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int libcdsb_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user