Skip to content
Snippets Groups Projects
Commit b052b30f authored by Bruce Cowan's avatar Bruce Cowan :airplane:
Browse files

Add double->byte and byte->double test

parent cdb235b9
No related branches found
No related tags found
No related merge requests found
/*
* SPDX-FileCopyrightText: 2020 Bruce Cowan <bruce@bcowan.me.uk>
* SPDX-License-Identifier: Apache-2.0
*/
#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define DOUBLE_TO_BYTES(d) ((uint8_t *) &(d))
#define BYTES_TO_DOUBLE(b) (*((double *) (b)))
int
main (void)
{
double pi = M_PI;
uint8_t *bytes = DOUBLE_TO_BYTES (pi);
printf ("Bytes are [");
for (int i = 0; i < 7; i++)
printf ("%02" PRIx8 ", ", bytes[i]);
printf ("%02" PRIx8 "]\n", bytes[7]);
double d = BYTES_TO_DOUBLE (bytes);
printf ("Converting back, the value is %f\n", d);
return 0;
}
# SPDX-FileCopyrightText: 2018, 2019 Bruce Cowan <bruce@bcowan.me.uk>
#
# SPDX-FileCopyrightText: 2018-2020 Bruce Cowan <bruce@bcowan.me.uk>
# SPDX-License-Identifier: CC0-1.0
executable('add', 'add.c', dependencies: utils_dep)
......@@ -7,6 +6,7 @@ executable('angle', 'angle.c', dependencies: libm)
executable('array-length', 'array-length.c', dependencies: types_dep)
executable('binary', 'binary.c')
executable('binary2', 'binary2.c', dependencies: utils_dep)
executable('bytedouble', 'bytedouble.c')
executable('complex', 'complex.c', dependencies: libm)
executable('doubles', 'doubles.c')
executable('einstein', 'einstein.c')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment