Skip to content

Commit

Permalink
_Generic
Browse files Browse the repository at this point in the history
  • Loading branch information
horta committed Feb 1, 2021
1 parent 7ff8922 commit e6d950e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 88
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ target_include_directories(logaddexp
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_link_libraries(logaddexp INTERFACE $<$<BOOL:${UNIX}>:m>)
target_compile_features(logaddexp INTERFACE c_std_11)

install(TARGETS logaddexp EXPORT logaddexp-targets)
install(DIRECTORY include/ DESTINATION include)
Expand Down
21 changes: 6 additions & 15 deletions include/logaddexp/logaddexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,12 @@ inline static double logaddexpss(double x, double y, double sx, double sy, doubl
{
return logaddexpgd(x, y, sx, sy, sign);
}
#define logaddexp(x, y) _Generic(x, float : logaddexpf((x), (y)), double : logaddexpd((x), (y)))

#define logaddexp(a, b) \
((sizeof(a) == sizeof(float) && sizeof(b) == sizeof(float)) ? logaddexpf(a, b) \
: logaddexpd(a, b))

#define logaddexps(x, y, sx, sy) \
((sizeof(x) == sizeof(float) && sizeof(y) == sizeof(float) && \
sizeof(sx) == sizeof(float) && sizeof(sy) == sizeof(float)) \
? logaddexpsf(x, y, sx, sy) \
: logaddexpsd(x, y, sx, sy))

#define logaddexpg(x, y, sx, sy, sign) \
((sizeof(x) == sizeof(float) && sizeof(y) == sizeof(float) && \
sizeof(sx) == sizeof(float) && sizeof(sy) == sizeof(float)) \
? logaddexpgf(x, y, sx, sy, sign) \
: logaddexpgd(x, y, sx, sy, sign))
#define logaddexps(x, y, sx, sy) \
_Generic(x, float : logaddexpsf((x), (y), (sx), (sy)), double : logaddexpsd((x), (y), (sx), (sy)))

#define logaddexpg(x, y, sx, sy, sign) \
_Generic(x, float : logaddexpgf((x), (y), (sx), (sy), (sign)), double : logaddexpgd((x), (y), (sx), (sy), (sign)))

#endif
2 changes: 1 addition & 1 deletion test/logaddexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int test_logaddexp_nan(void)
if (!isnan(logaddexp(NAN, 0)))
return 1;

if (!isnan(logaddexp(0, NAN)))
if (!isnan(logaddexp(0., NAN)))
return 1;

if (!isnan(logaddexp(NAN, NAN)))
Expand Down

0 comments on commit e6d950e

Please sign in to comment.