Skip to content

Commit

Permalink
Use fmt library in Common2::DoubleToStr()
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoEAF committed Sep 15, 2020
1 parent b169f38 commit 244ff1d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "include/boost/compute"]
path = compute
url = https://github.com/boostorg/compute
[submodule "external_libs/fmt"]
path = external_libs/fmt
url = https://github.com/fmtlib/fmt.git
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ if(WIN32 AND (MINGW OR CYGWIN))
TARGET_LINK_LIBRARIES(_lightgbm IPHLPAPI)
endif()


if(BUILD_FOR_R)
if(MSVC)
TARGET_LINK_LIBRARIES(_lightgbm ${LIBR_MSVC_CORE_LIBRARY})
Expand All @@ -323,6 +324,11 @@ if(BUILD_FOR_R)
endif(MSVC)
endif(BUILD_FOR_R)

# fmtlib/fmt
add_subdirectory(external_libs/fmt)
TARGET_LINK_LIBRARIES(lightgbm PUBLIC fmt::fmt)
TARGET_LINK_LIBRARIES(_lightgbm PUBLIC fmt::fmt)

install(TARGETS lightgbm _lightgbm
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
Expand Down
1 change: 1 addition & 0 deletions external_libs/fmt
Submodule fmt added at f67443
11 changes: 5 additions & 6 deletions include/LightGBM/utils/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef LIGHTGBM_UTILS_COMMON_FUN_H_
#define LIGHTGBM_UTILS_COMMON_FUN_H_

#include "../../../fmt/include/fmt/core.h"
#include <LightGBM/utils/log.h>
#include <LightGBM/utils/openmp_wrapper.h>

Expand Down Expand Up @@ -408,13 +409,11 @@ inline static void Int32ToStr(int32_t value, char* buffer) {
Uint32ToStr(u, buffer);
}



inline static void DoubleToStr(double value, char* buffer, size_t buffer_len) {
#ifdef _MSC_VER
int num_chars = sprintf_s(buffer, buffer_len, "%.17g", value);
#else
int num_chars = snprintf(buffer, buffer_len, "%.17g", value);
#endif
CHECK_GE(num_chars, 0);
const std::string s = fmt::format("{:.17g}", value);
s.copy(buffer, buffer_len);
}

inline static const char* SkipSpaceAndTab(const char* p) {
Expand Down

0 comments on commit 244ff1d

Please sign in to comment.