Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix double promotion warnings #56

Merged
merged 8 commits into from
Dec 13, 2023
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ zephyr_library_sources(
)
#zephyr_library_sources_ifdef(CONFIG_ZSL_SINGLE_PRECISION src/zsl_todo.c)

zephyr_library_compile_options_ifdef(CONFIG_ZSL_SINGLE_PRECISION $<$<STREQUAL:${CMAKE_C_COMPILER_ID},GNU>:-fsingle-precision-constant>)
zephyr_library_compile_options_ifdef(CONFIG_ZSL_SINGLE_PRECISION $<$<STREQUAL:${CMAKE_C_COMPILER_ID},ARMClang>:-cl-single-precision-constant>)

zephyr_library_link_libraries(ZSCILIB)
target_link_libraries(ZSCILIB INTERFACE zephyr_interface)
endif()
4 changes: 2 additions & 2 deletions include/zsl/interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ struct zsl_interp_xyc {

/**
* @brief Calculates a number between two numbers using linear interpolation,
* where 't' is the interpolation factor between 0.0f and 1.0f.
* where 't' is the interpolation factor between 0.0 and 1.0.
*
* @param v0 The lower value used when interpolating.
* @param v1 The upper value used when interpolating.
* @param t The interpolation factor between 0.0f and 1.0f.
* @param t The interpolation factor between 0.0 and 1.0.
* @param v Pointer to the placeholder for the interpolated value.
*
* @return 0 on success, error code on error.
Expand Down
2 changes: 2 additions & 0 deletions include/zsl/zsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ typedef double zsl_real_t;
#define ZSL_TANH tanhf
#define ZSL_ERF erff
#define ZSL_FMA fmaf
#define ZSL_EXPM1 expm1f
#else
#define ZSL_CEIL ceil
#define ZSL_FLOOR floor
Expand All @@ -101,6 +102,7 @@ typedef double zsl_real_t;
#define ZSL_TANH tanh
#define ZSL_ERF erf
#define ZSL_FMA fma
#define ZSL_EXPM1 expm1
#endif


Expand Down
2 changes: 1 addition & 1 deletion samples/orientation/apitest/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static zsl_real_t _mahn_intfb[3] = { 0.0, 0.0, 0.0 };
static struct zsl_fus_mahn_cfg mahn_cfg = {
.kp = 0.235,
.ki = 0.02,
.integral_limit = 10000.0f,
.integral_limit = 10000.0,
.intfb = {
.sz = 3,
.data = _mahn_intfb,
Expand Down
98 changes: 49 additions & 49 deletions src/colorimetry/conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ zsl_clr_conv_ct_xyz(zsl_real_t ct, enum zsl_clr_obs obs, struct zsl_clr_xyz *xyz
d_wl_m5 = d_wl_m * d_wl_m * d_wl_m * d_wl_m * d_wl_m;
/* Calculate black-body value. Source: Bruce Lindbloom */
bbody = c1 / (d_wl_m5 * 1.0e-12 *
(expm1(c2 / (ct * d_wl_m * 1.0e-3))));
(ZSL_EXPM1(c2 / (ct * d_wl_m * 1.0e-3))));
/* Calculate XYZ tristimulus using the std observer model. */
xyz->xyz_x += (bbody * obs_data->data[i].xyz_x);
xyz->xyz_y += (bbody * obs_data->data[i].xyz_y);
Expand Down Expand Up @@ -794,11 +794,11 @@ zsl_clr_conv_cct_xyy(struct zsl_clr_cct *cct, enum zsl_clr_obs obs, struct zsl_c
delta.uv60_v = uv0.uv60_v - uv1.uv60_v;
final.uv60_u = uv0.uv60_u -
cct->duv * (delta.uv60_v /
sqrt(delta.uv60_u * delta.uv60_u +
ZSL_SQRT(delta.uv60_u * delta.uv60_u +
delta.uv60_v * delta.uv60_v));
final.uv60_v = uv0.uv60_v +
cct->duv * (delta.uv60_u /
sqrt(delta.uv60_u * delta.uv60_u +
ZSL_SQRT(delta.uv60_u * delta.uv60_u +
delta.uv60_v * delta.uv60_v));

/*
Expand Down Expand Up @@ -882,7 +882,7 @@ zsl_clr_conv_uv60_cct_mccamy(struct zsl_clr_uv60 *uv, struct zsl_clr_cct *cct)
/* Calculate cct using McCamy's approximation. */
rc = zsl_clr_conv_uv60_xyy(uv, &xyy);
n = (xyy.xyy_x - 0.3320) / (0.1858 - xyy.xyy_y);
cct->cct = (449.0 * pow(n, 3) + 3525.0 * pow(n, 2) +
cct->cct = (449.0 * ZSL_POW(n, 3) + 3525.0 * ZSL_POW(n, 2) +
6823.3 * n + 5520.33);

return 0;
Expand Down Expand Up @@ -917,19 +917,19 @@ zsl_clr_conv_uv60_cct_ohno2011(struct zsl_clr_uv60 *uv, struct zsl_clr_cct *cct)
memset(cct, 0, sizeof *cct);

/* Calculate L_fp. */
l_fp = sqrt((uv->uv60_u - 0.292) * (uv->uv60_u - 0.292) +
l_fp = ZSL_SQRT((uv->uv60_u - 0.292) * (uv->uv60_u - 0.292) +
(uv->uv60_v - 0.24) * (uv->uv60_v - 0.24));

/* Calculate the black-body spectral radiance using k[0] constants.
* Note: This formula uses an approximation since we don't know
* the CCT. */
a_1 = atan((uv->uv60_v - 0.24) / (uv->uv60_u - 0.292));
a = a_1 >= 0.0 ? a_1 : a_1 + M_PI;
l_bb = zsl_clr_conv_xyy_cct_ohno_2011_data[0][6] * pow(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[0][5] * pow(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[0][4] * pow(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[0][3] * pow(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[0][2] * pow(a, 2) +
l_bb = zsl_clr_conv_xyy_cct_ohno_2011_data[0][6] * ZSL_POW(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[0][5] * ZSL_POW(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[0][4] * ZSL_POW(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[0][3] * ZSL_POW(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[0][2] * ZSL_POW(a, 2) +
zsl_clr_conv_xyy_cct_ohno_2011_data[0][1] * a +
zsl_clr_conv_xyy_cct_ohno_2011_data[0][0];

Expand All @@ -941,34 +941,34 @@ zsl_clr_conv_uv60_cct_ohno2011(struct zsl_clr_uv60 *uv, struct zsl_clr_cct *cct)

/* Calculate T1 and DT_c1 delta depending on the value of a. */
if (a < 2.54) {
t1 = 1 / (zsl_clr_conv_xyy_cct_ohno_2011_data[1][6] * pow(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[1][5] * pow(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[1][4] * pow(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[1][3] * pow(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[1][2] * pow(a, 2) +
t1 = 1 / (zsl_clr_conv_xyy_cct_ohno_2011_data[1][6] * ZSL_POW(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[1][5] * ZSL_POW(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[1][4] * ZSL_POW(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[1][3] * ZSL_POW(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[1][2] * ZSL_POW(a, 2) +
zsl_clr_conv_xyy_cct_ohno_2011_data[1][1] * a +
zsl_clr_conv_xyy_cct_ohno_2011_data[1][0]);
dt_c1 = (zsl_clr_conv_xyy_cct_ohno_2011_data[3][6] * pow(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[3][5] * pow(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[3][4] * pow(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[3][3] * pow(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[3][2] * pow(a, 2) +
dt_c1 = (zsl_clr_conv_xyy_cct_ohno_2011_data[3][6] * ZSL_POW(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[3][5] * ZSL_POW(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[3][4] * ZSL_POW(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[3][3] * ZSL_POW(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[3][2] * ZSL_POW(a, 2) +
zsl_clr_conv_xyy_cct_ohno_2011_data[3][1] * a +
zsl_clr_conv_xyy_cct_ohno_2011_data[3][0]) *
(l_bb + 0.01) / l_p * cct->duv / 0.01;
} else {
t1 = 1 / (zsl_clr_conv_xyy_cct_ohno_2011_data[2][6] * pow(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[2][5] * pow(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[2][4] * pow(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[2][3] * pow(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[2][2] * pow(a, 2) +
t1 = 1 / (zsl_clr_conv_xyy_cct_ohno_2011_data[2][6] * ZSL_POW(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[2][5] * ZSL_POW(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[2][4] * ZSL_POW(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[2][3] * ZSL_POW(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[2][2] * ZSL_POW(a, 2) +
zsl_clr_conv_xyy_cct_ohno_2011_data[2][1] * a +
zsl_clr_conv_xyy_cct_ohno_2011_data[2][0]);
dt_c1 = (zsl_clr_conv_xyy_cct_ohno_2011_data[4][6] * pow(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[4][5] * pow(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[4][4] * pow(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[4][3] * pow(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[4][2] * pow(a, 2) +
dt_c1 = (zsl_clr_conv_xyy_cct_ohno_2011_data[4][6] * ZSL_POW(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[4][5] * ZSL_POW(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[4][4] * ZSL_POW(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[4][3] * ZSL_POW(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[4][2] * ZSL_POW(a, 2) +
zsl_clr_conv_xyy_cct_ohno_2011_data[4][1] * a +
zsl_clr_conv_xyy_cct_ohno_2011_data[4][0]) *
(l_bb + 0.01) / l_p * cct->duv / 0.01;
Expand All @@ -980,22 +980,22 @@ zsl_clr_conv_uv60_cct_ohno2011(struct zsl_clr_uv60 *uv, struct zsl_clr_cct *cct)

/* Calculate DT_c2 depending on positive or negative Duv. */
if (cct->duv >= 0.0) {
dt_c2 = (zsl_clr_conv_xyy_cct_ohno_2011_data[5][6] * pow(c, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[5][5] * pow(c, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[5][4] * pow(c, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[5][3] * pow(c, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[5][2] * pow(c, 2) +
dt_c2 = (zsl_clr_conv_xyy_cct_ohno_2011_data[5][6] * ZSL_POW(c, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[5][5] * ZSL_POW(c, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[5][4] * ZSL_POW(c, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[5][3] * ZSL_POW(c, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[5][2] * ZSL_POW(c, 2) +
zsl_clr_conv_xyy_cct_ohno_2011_data[5][1] * c +
zsl_clr_conv_xyy_cct_ohno_2011_data[5][0]);
} else {
dt_c2 = (zsl_clr_conv_xyy_cct_ohno_2011_data[6][6] * pow(c, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[6][5] * pow(c, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[6][4] * pow(c, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[6][3] * pow(c, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[6][2] * pow(c, 2) +
dt_c2 = (zsl_clr_conv_xyy_cct_ohno_2011_data[6][6] * ZSL_POW(c, 6) +
zsl_clr_conv_xyy_cct_ohno_2011_data[6][5] * ZSL_POW(c, 5) +
zsl_clr_conv_xyy_cct_ohno_2011_data[6][4] * ZSL_POW(c, 4) +
zsl_clr_conv_xyy_cct_ohno_2011_data[6][3] * ZSL_POW(c, 3) +
zsl_clr_conv_xyy_cct_ohno_2011_data[6][2] * ZSL_POW(c, 2) +
zsl_clr_conv_xyy_cct_ohno_2011_data[6][1] * c +
zsl_clr_conv_xyy_cct_ohno_2011_data[6][0]) *
pow(cct->duv / 0.03, 2);
ZSL_POW(cct->duv / 0.03, 2);
}

/* Assign the final correlated color temperature. */
Expand Down Expand Up @@ -1124,7 +1124,7 @@ zsl_clr_conv_uv60_cct_ohno2014(struct zsl_clr_uv60 *uv, struct zsl_clr_cct *cct)
zsl_clr_conv_ct_uv_ohno_2014_data[match_idx - 1][2]) *
(zsl_clr_conv_ct_uv_ohno_2014_data[match_idx + 1][2] -
zsl_clr_conv_ct_uv_ohno_2014_data[match_idx - 1][2]));
l = sqrt(l);
l = ZSL_SQRT(l);

x = ((d_prev * d_prev) - (d_next * d_next) + (l * l)) / (2.0 * l);

Expand All @@ -1134,14 +1134,14 @@ zsl_clr_conv_uv60_cct_ohno2014(struct zsl_clr_uv60 *uv, struct zsl_clr_cct *cct)
(x / l);

/* Calculate Duv. */
l_fp = sqrt((uv->uv60_u - 0.292) * (uv->uv60_u - 0.292) +
l_fp = ZSL_SQRT((uv->uv60_u - 0.292) * (uv->uv60_u - 0.292) +
(uv->uv60_v - 0.24) * (uv->uv60_v - 0.24));
a = acos((uv->uv60_u - 0.292) / l_fp);
l_bb = zsl_clr_conv_xyy_cct_ohno_2014_data[6] * pow(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2014_data[5] * pow(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2014_data[4] * pow(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2014_data[3] * pow(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2014_data[2] * pow(a, 2) +
a = ZSL_ACOS((uv->uv60_u - 0.292) / l_fp);
l_bb = zsl_clr_conv_xyy_cct_ohno_2014_data[6] * ZSL_POW(a, 6) +
zsl_clr_conv_xyy_cct_ohno_2014_data[5] * ZSL_POW(a, 5) +
zsl_clr_conv_xyy_cct_ohno_2014_data[4] * ZSL_POW(a, 4) +
zsl_clr_conv_xyy_cct_ohno_2014_data[3] * ZSL_POW(a, 3) +
zsl_clr_conv_xyy_cct_ohno_2014_data[2] * ZSL_POW(a, 2) +
zsl_clr_conv_xyy_cct_ohno_2014_data[1] * a +
zsl_clr_conv_xyy_cct_ohno_2014_data[0];

Expand Down
39 changes: 19 additions & 20 deletions src/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ zsl_interp_lerp(zsl_real_t v0, zsl_real_t v1, zsl_real_t t, zsl_real_t *v)
int rc;

/* Ensure t = 0.0..1.0 */
if ((t < 0.0f) || (t > 1.0f)) {
if ((t < 0.0) || (t > 1.0)) {
rc = -EINVAL;
*v = NAN;
goto err;
}

*v = (1.0f - t) * v0 + t * v1;
*v = (1.0 - t) * v0 + t * v1;

return 0;
err:
Expand Down Expand Up @@ -105,7 +105,7 @@ zsl_interp_nn(struct zsl_interp_xy *xy1, struct zsl_interp_xy *xy3,

/* Make sure there is a delta x between xy1 and xy3. */
delta = xy3->x - xy1->x;
if (delta < 1E-6F && -delta < 1E-6F) {
if (delta < 1E-6 && -delta < 1E-6) {
rc = -EINVAL;
*y2 = NAN;
goto err;
Expand All @@ -118,7 +118,7 @@ zsl_interp_nn(struct zsl_interp_xy *xy1, struct zsl_interp_xy *xy3,
}

/* Determine which value is closest, rounding up on 0.5. */
*y2 = x2 >= (xy1->x * 1.5f) ? xy3->y : xy1->y;
*y2 = x2 >= (xy1->x * 1.5) ? xy3->y : xy1->y;

return 0;
err:
Expand Down Expand Up @@ -160,7 +160,7 @@ zsl_interp_lin_y(struct zsl_interp_xy *xy1, struct zsl_interp_xy *xy3,

/* Make sure there is a delta on x between xy1 and xy3. */
delta = xy3->x - xy1->x;
if (delta < 1E-6F && -delta < 1E-6F) {
if (delta < 1E-6 && -delta < 1E-6) {
rc = -EINVAL;
*y2 = NAN;
goto err;
Expand Down Expand Up @@ -221,7 +221,7 @@ zsl_interp_lin_x(struct zsl_interp_xy *xy1, struct zsl_interp_xy *xy3,

/* Make sure there is a delta on x between xy1 and xy3. */
delta = xy3->x - xy1->x;
if (delta < 1E-6F && -delta < 1E-6F) {
if (delta < 1E-6 && -delta < 1E-6) {
rc = -EINVAL;
*x2 = NAN;
goto err;
Expand Down Expand Up @@ -275,12 +275,11 @@ zsl_interp_cubic_calc(struct zsl_interp_xyc xyc[], size_t n, zsl_real_t yp1,
goto err;
}

/* TODO: Remove 'f' restrictions? */
if (yp1 > 0.99e30f) {
xyc[0].y2 = u[0] = 0.0f;
if (yp1 > 0.99e30) {
xyc[0].y2 = u[0] = 0.0;
} else {
xyc[0].y2 = -0.5f;
u[0] = (3.0f / (xyc[1].x - xyc[0].x)) *
xyc[0].y2 = -0.5;
u[0] = (3.0 / (xyc[1].x - xyc[0].x)) *
((xyc[1].y - xyc[0].y) / (xyc[1].x - xyc[0].x) - yp1);
}

Expand All @@ -289,23 +288,23 @@ zsl_interp_cubic_calc(struct zsl_interp_xyc xyc[], size_t n, zsl_real_t yp1,
zsl_real_t x_i_im1 = xyc[i].x - xyc[i - 1].x;
zsl_real_t x_ip1_im1 = xyc[i + 1].x - xyc[i - 1].x;
sigma = x_i_im1 / x_ip1_im1;
p = sigma * xyc[i - 1].y2 + 2.0f;
xyc[i].y2 = (sigma - 1.0f) / p;
p = sigma * xyc[i - 1].y2 + 2.0;
xyc[i].y2 = (sigma - 1.0) / p;
u[i] = (xyc[i + 1].y - xyc[i].y) / (xyc[i + 1].x - xyc[i].x) -
(xyc[i].y - xyc[i - 1].y) / (x_i_im1);
u[i] = (6.0f * u[i] / (x_ip1_im1) - sigma * u[i - 1]) / p;
u[i] = (6.0 * u[i] / (x_ip1_im1) - sigma * u[i - 1]) / p;
}

if (ypn > 0.99e30f) {
qn = un = 0.0f;
if (ypn > 0.99e30) {
qn = un = 0.0;
} else {
qn = 0.5f;
un = (3.0f / (xyc[n - 1].x - xyc[n - 2].x)) *
qn = 0.5;
un = (3.0 / (xyc[n - 1].x - xyc[n - 2].x)) *
(ypn - (xyc[n - 1].y -
xyc[n - 2].y) / (xyc[n - 1].x - xyc[n - 2].x));
}

xyc[n - 1].y2 = (un - qn * u[n - 2]) / (qn * xyc[n - 2].y2 + 1.0f);
xyc[n - 1].y2 = (un - qn * u[n - 2]) / (qn * xyc[n - 2].y2 + 1.0);

for (k = n - 2; k >= 0; k--) {
xyc[k].y2 = xyc[k].y2 * xyc[k + 1].y2 + u[k];
Expand Down Expand Up @@ -392,7 +391,7 @@ zsl_interp_cubic_arr(struct zsl_interp_xyc xyc[], size_t n,
/* Interpolate for y based on a, b using prev. calculated y2 vals. */
*y = a * xyc[klo].y + b * xyc[khi].y +
((a * a * a - a) * xyc[klo].y2 + (b * b * b - b) *
xyc[khi].y2) * (h * h) / 6.0f;
xyc[khi].y2) * (h * h) / 6.0;

return 0;
err:
Expand Down
2 changes: 1 addition & 1 deletion src/matrices.c
Original file line number Diff line number Diff line change
Expand Up @@ -1941,7 +1941,7 @@ zsl_mtx_print(struct zsl_mtx *m)
return -EINVAL;
}
/* Print the current floating-point value. */
printf("%f ", x);
printf("%f ", (double)x);
}
printf("\n");
}
Expand Down
2 changes: 1 addition & 1 deletion src/orientation/euler.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ int zsl_eul_to_vec(struct zsl_euler *e, struct zsl_vec *v)

int zsl_eul_print(struct zsl_euler *e)
{
printf("(%f, %f, %f)\n\n", e->x, e->y, e->z);
printf("(%f, %f, %f)\n\n", (double)e->x, (double)e->y, (double)e->z);
return 0;
}
3 changes: 2 additions & 1 deletion src/orientation/quaternions.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ int zsl_quat_from_axis_angle(struct zsl_vec *a, zsl_real_t *b,

int zsl_quat_print(struct zsl_quat *q)
{
printf("%.16f + %.16f i + %.16f j + %.16f k\n", q->r, q->i, q->j, q->k);
printf("%.16f + %.16f i + %.16f j + %.16f k\n",
(double)q->r, (double)q->i, (double)q->j, (double)q->k);

return 0;
}
12 changes: 11 additions & 1 deletion src/physics/atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ zsl_phy_atom_bohr_orb_radius(uint8_t z, uint8_t n, zsl_real_t *r)
return -EINVAL;
}

#ifdef CONFIG_ZSL_SINGLE_PRECISION
/*
* Numbers get too small for single percision so multiply a large
* constant in to the numerator and denomerator to prevent numbers
* from going to 0.0f
*/
*r = ((zsl_real_t) n * (zsl_real_t) n * ZSL_RED_PLANCK * 1E30 *
ZSL_RED_PLANCK * 1E9) / ((zsl_real_t) z * ZSL_COULOMB *
ZSL_E_CHARGE * 1E30 * ZSL_E_CHARGE * ZSL_E_MASS);
#else
*r = ((zsl_real_t) n * (zsl_real_t) n * ZSL_RED_PLANCK *
ZSL_RED_PLANCK * 1E9) / ((zsl_real_t) z * ZSL_COULOMB *
ZSL_E_CHARGE * ZSL_E_CHARGE * ZSL_E_MASS);

#endif

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vectors.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ int zsl_vec_sort(struct zsl_vec *v, struct zsl_vec *w)
int zsl_vec_print(struct zsl_vec *v)
{
for (size_t g = 0; g < v->sz; g++) {
printf("%f ", v->data[g]);
printf("%f ", (double)v->data[g]);
}
printf("\n\n");

Expand Down
Loading
Loading