Skip to content
Snippets Groups Projects
Commit c8c0bbec authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added float16.h

parent 3b450c40
No related branches found
No related tags found
1 merge request!85M214003/develop
......@@ -50,6 +50,7 @@ list( APPEND cdi_src_files
exse.h
extra.h
extralib.c
float16.h
file.c
file.h
gaussian_latitudes.c
......
......@@ -127,6 +127,7 @@ libcdi_la_SOURCES = \
exse.h \
extra.h \
extralib.c \
float16.h \
file.c \
file.h \
gaussian_latitudes.c \
......
......@@ -170,9 +170,19 @@ binWriteFlt64(int fileID, int byteswap, size_t size, double *ptr)
{
if (byteswap) swap8byte(ptr, size);
fileWrite(fileID, (void *) ptr, 8 * size);
return 0;
}
#ifdef HAVE_FLOAT16
int
binWriteFlt16(int fileID, int byteswap, size_t size, _Float16 *ptr)
{
if (byteswap) swap4byte(ptr, size);
fileWrite(fileID, (void *) ptr, 2 * size);
return 0;
}
#endif
/*
* Local Variables:
* c-file-style: "Java"
......
......@@ -3,6 +3,7 @@
#include <stdio.h>
#include <inttypes.h>
#include "float16.h"
#ifndef HOST_ENDIANNESS
#ifdef __cplusplus
......@@ -30,6 +31,10 @@ int binWriteInt64(int fileID, int byteswap, size_t size, int64_t *ptr);
int binWriteFlt32(int fileID, int byteswap, size_t size, float *ptr);
int binWriteFlt64(int fileID, int byteswap, size_t size, double *ptr);
#ifdef HAVE_FLOAT16
int binWriteFlt16(int fileID, int byteswap, size_t size, _Float16 *ptr);
#endif
#endif /* BINARY_H */
/*
* Local Variables:
......
#ifndef FLOAT16_H
#define FLOAT16_H
// CAUTION: __is_identifier behaves opposite how you would expect!
// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
// the compiler and '1' otherwise.
// borrowed from LLVM __config header under Apache license 2.
// (https://www.mend.io/blog/top-10-apache-license-questions-answered/)
#ifndef __is_identifier // Optional of course.
#define __is_identifier(x) 1 // Compatibility with non-clang compilers.
#endif
// More sensible macro for keyword detection
#define __has_keyword(__x) !(__is_identifier(__x))
// map a half float type, if available, to _OptionalHalfFloatType
#if __has_keyword(_Float16)
#define HAVE_FLOAT16
#endif
#endif
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