07-28-2022, 04:04 PM
(This post was last modified: 07-28-2022, 04:05 PM by fatman2021.)
Updated floating point math support:
Code: (Select All)
' float128 math functions
/'
void float128_from_double(float128* a, double* b) {
*a = (float128)(*(double*)(b));
}
'/
def SYSTEM_BUS_T.k_float128_from_double(a as FLOAT128 ptr, b as float ptr)
*a = *b
end def
/'
void float128_to_double(float128* a, double* b) {
*a = (double)(*(float128*)(b));
}
'/
def SYSTEM_BUS_T.k_float128_to_double(a as FLOAT128 ptr, b as float ptr)
*b = *a
end def
/'
void float128_add(float128* a, float128* b, float128* c) {
*c = *a + *b;
}
'/
def SYSTEM_BUS_T.k_float128_add(a as FLOAT128 ptr, b as FLOAT128 ptr, c as FLOAT128 ptr)
*c = *a + *b
end def
/'
void float128_sub(float128* a, float128* b, float128* c) {
*c = *a - *b;
}
'/
def SYSTEM_BUS_T.k_float128_sub(a as FLOAT128 ptr, b as FLOAT128 ptr, c as FLOAT128 ptr)
*c = *a - *b
end def
/'
void float128_abs(float128* a, float128* b) {
if (*a > 0) {
*b = *a;
} else {
*b = -*a;
}
}
'/
def SYSTEM_BUS_T.k_float128_abs(a as FLOAT128 ptr, b as FLOAT128 ptr)
if (*a > 0) then
*b = *a
else
*b = -*a
end if
end def
/'
void float128_mul(float128* a, float128* b, float128* c) {
*c = *a * *b;
}
'/
def SYSTEM_BUS_T.k_float128_mul(a as FLOAT128 ptr, b as FLOAT128 ptr, c as FLOAT128 ptr)
*c = *a * *b
end def
/'
void float128_div(float128* a, float128* b, float128* c) {
*c = *a / *b;
}
'/
def SYSTEM_BUS_T.k_float128_div(a as FLOAT128 ptr, b as FLOAT128 ptr, c as FLOAT128 ptr)
*c = *a / *b
end def
/'
int float128_cmp(float128* a, float128* b) {
if (*a > *b) {
return 1;
} else if (*a < *b) {
return -1;
} else {
return 0;
}
}
'/
proc SYSTEM_BUS_T.k_float128_cmp(a as FLOAT128 ptr, b as FLOAT128 ptr) as int_t
if (*a > *b) then
return 1
elseif (*a < *b) then
return -1
else
return 0
endif
end proc
' float256 math functions
/'
void float256_from_double(float256* a, double* b) {
*a = (float256)(*(double*)(b));
}
'/
def SYSTEM_BUS_T.k_float256_from_double(a as FLOAT256 ptr, b as float ptr)
*a = *b
end def
/'
void float256_to_double(float256* a, double* b) {
*a = (double)(*(float256*)(b));
}
'/
def SYSTEM_BUS_T.k_float256_to_double(a as FLOAT256 ptr, b as float ptr)
*b = *a
end def
/'
void float256_add(float256* a, float256* b, float256* c) {
*c = *a + *b;
}
'/
def SYSTEM_BUS_T.k_float256_add(a as FLOAT256 ptr, b as FLOAT256 ptr, c as FLOAT256 ptr)
*c = *a + *b
end def
/'
void float256_sub(float256* a, float256* b, float256* c) {
*c = *a - *b;
}
'/
def SYSTEM_BUS_T.k_float256_sub(a as FLOAT256 ptr, b as FLOAT256 ptr, c as FLOAT256 ptr)
*c = *a - *b
end def
/'
void float256_abs(float256* a, float256* b) {
if (*a > 0) {
*b = *a;
} else {
*b = -*a;
}
}
'/
def SYSTEM_BUS_T.k_float256_abs(a as FLOAT256 ptr, b as FLOAT256 ptr)
if (*a > 0) then
*b = *a
else
*b = -*a
end if
end def
/'
void float256_mul(float256* a, float256* b, float256* c) {
*c = *a * *b;
}
'/
def SYSTEM_BUS_T.k_float256_mul(a as FLOAT256 ptr, b as FLOAT256 ptr, c as FLOAT256 ptr)
*c = *a * *b
end def
/'
void float256_div(float256* a, float256* b, float256* c) {
*c = *a / *b;
}
'/
def SYSTEM_BUS_T.k_float256_div(a as FLOAT256 ptr, b as FLOAT256 ptr, c as FLOAT256 ptr)
*c = *a / *b
end def
/'
int float256_cmp(float256* a, float256* b) {
if (*a > *b) {
return 1;
} else if (*a < *b) {
return -1;
} else {
return 0;
}
}
'/
proc SYSTEM_BUS_T.k_float256_cmp(a as FLOAT256 ptr, b as FLOAT256 ptr) as int_t
if (*a > *b) then
return 1
elseif (*a < *b) then
return -1
else
return 0
endif
end proc
' float512 math functions
/'
void float512_from_double(float512* a, double* b) {
*a = (float512)(*(double*)(b));
}
'/
def SYSTEM_BUS_T.k_float512_from_double(a as FLOAT512 ptr, b as float ptr)
*a = *b
end def
/'
void float512_to_double(float512* a, double* b) {
*a = (double)(*(float512*)(b));
}
'/
def SYSTEM_BUS_T.k_float512_to_double(a as FLOAT512 ptr, b as float ptr)
*b = *a
end def
/'
void float512_add(float512* a, float512* b, float512* c) {
*c = *a + *b;
}
'/
def SYSTEM_BUS_T.k_float512_add(a as FLOAT512 ptr, b as FLOAT512 ptr, c as FLOAT512 ptr)
*c = *a + *b
end def
/'
void float512_sub(float512* a, float512* b, float512* c) {
*c = *a - *b;
}
'/
def SYSTEM_BUS_T.k_float512_sub(a as FLOAT512 ptr, b as FLOAT512 ptr, c as FLOAT512 ptr)
*c = *a - *b
end def
/'
void float512_abs(float512* a, float512* b) {
if (*a > 0) {
*b = *a;
} else {
*b = -*a;
}
}
'/
def SYSTEM_BUS_T.k_float512_abs(a as FLOAT512 ptr, b as FLOAT512 ptr)
if (*a > 0) then
*b = *a
else
*b = -*a
end if
end def
/'
void float512_mul(float512* a, float512* b, float512* c) {
*c = *a * *b;
}
'/
def SYSTEM_BUS_T.k_float512_mul(a as FLOAT512 ptr, b as FLOAT512 ptr, c as FLOAT512 ptr)
*c = *a * *b
end def
/'
void float512_div(float512* a, float512* b, float512* c) {
*c = *a / *b;
}
'/
def SYSTEM_BUS_T.k_float512_div(a as FLOAT512 ptr, b as FLOAT512 ptr, c as FLOAT512 ptr)
*c = *a / *b
end def
/'
int float512_cmp(float512* a, float512* b) {
if (*a > *b) {
return 1;
} else if (*a < *b) {
return -1;
} else {
return 0;
}
}
'/
proc SYSTEM_BUS_T.k_float512_cmp(a as FLOAT512 ptr, b as FLOAT512 ptr) as int_t
if (*a > *b) then
return 1
elseif (*a < *b) then
return -1
else
return 0
endif
end proc