Skip to content

WIP Refactor Version 2.0 #53

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

Open
wants to merge 71 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
34ea81b
Removed matrix files
JoshuaSBrown Apr 27, 2019
e7f1564
Switched file readers to using eigen matrices as opposed to local mat…
JoshuaSBrown Apr 27, 2019
094177e
Switched to eigen matrices in main
JoshuaSBrown Apr 27, 2019
47257b0
Removed matrix tests
JoshuaSBrown Apr 28, 2019
0ad1283
Updated main and qc_functions to use Eigen matrix and vector classes
JoshuaSBrown Apr 28, 2019
f99db21
Added matrix helper functions
JoshuaSBrown Apr 28, 2019
e77984a
Updated tests and qc_functions.cpp
JoshuaSBrown Apr 28, 2019
8239b14
Fixing compiler errors
JoshuaSBrown Apr 29, 2019
23f393f
First successful compile
JoshuaSBrown Apr 29, 2019
47e3078
Add testing to log reader
JoshuaSBrown Apr 30, 2019
3bcf329
Added test for overlap
JoshuaSBrown Apr 30, 2019
9d70476
Added overlap test
JoshuaSBrown Apr 30, 2019
c84823d
checkpoint
JoshuaSBrown Apr 30, 2019
54b55e5
Fixed error that was introduced
JoshuaSBrown Apr 30, 2019
e13daaa
Updated print statment and fixed error
JoshuaSBrown May 1, 2019
eae3804
Updated version
JoshuaSBrown May 1, 2019
c9ba317
Added switch for printing all transfer integrals
JoshuaSBrown May 1, 2019
7797dae
Add eigen as a package to ci
JoshuaSBrown May 1, 2019
9cbfb04
Added eigen to ci development stage
JoshuaSBrown May 1, 2019
ab1c42b
Corrected formatting of print all
JoshuaSBrown May 1, 2019
c71c9ae
UPdate eigen install in travis
JoshuaSBrown May 2, 2019
43745c9
fixing eigen includes
JoshuaSBrown May 3, 2019
71238ec
Fix cmake eigen call
JoshuaSBrown May 3, 2019
4188483
Fixed problem when reading overlap matrix with only a few coefficients
JoshuaSBrown May 14, 2019
e97a27d
Fixed error in script with J and, dimensions of matrices
JoshuaSBrown May 22, 2019
95fd3bd
fixed script
JoshuaSBrown May 22, 2019
c458d90
Temporary changes
JoshuaSBrown May 23, 2019
fcc12f2
Removed unused function
JoshuaSBrown May 23, 2019
6a801be
Fixed error, removed cout lines unneeded, added extra test
JoshuaSBrown May 23, 2019
1d8fcc5
Cleanup comments
JoshuaSBrown May 30, 2019
02f93fd
Kept updated version
JoshuaSBrown Feb 11, 2020
61e115a
Added profiling options, for gprof
JoshuaSBrown Feb 11, 2020
e5d915b
Deleted comments
JoshuaSBrown Feb 11, 2020
4195c01
Success compiling
JoshuaSBrown Jun 24, 2020
3c14cae
Fixed make target tests
JoshuaSBrown Jun 24, 2020
0a142dd
checkpoint
JoshuaSBrown Jul 9, 2020
ecade90
update
JoshuaSBrown Jul 12, 2020
7eb2ff5
Success compile
JoshuaSBrown Jul 12, 2020
c9ebdf6
Added Catch2 submodule
JoshuaSBrown Jul 15, 2020
ccfdb70
Added catch2 testing framework
JoshuaSBrown Jul 15, 2020
e63c815
Added elements tests
JoshuaSBrown Jul 16, 2020
adeaa09
Added elements test
JoshuaSBrown Jul 16, 2020
430cd19
GroupType assignment completed
JoshuaSBrown Jul 17, 2020
d08e466
Group assignment test now working
JoshuaSBrown Jul 17, 2020
61b8217
Added atom_system for handling basis functions and other improvements
JoshuaSBrown Jul 18, 2020
7c4ac40
Make handling of basis function assignment more refined, and add checks
JoshuaSBrown Jul 20, 2020
a4a3ed4
Cleanup swap
JoshuaSBrown Jul 23, 2020
b8119b8
Add test files
JoshuaSBrown Jul 24, 2020
e9f9fd3
Add missing header file
JoshuaSBrown Jul 25, 2020
7d18f35
Small fix to CMakeLists.txt
JoshuaSBrown Jul 25, 2020
7c6d40e
Add back missing executable
JoshuaSBrown Jul 25, 2020
2dc0765
Add CMakeLists.txt file for binary
JoshuaSBrown Jul 26, 2020
89d55e7
Switch project name to catnip as opposed to calcJ
JoshuaSBrown Jul 26, 2020
2b084ae
move calcJ config file to catnip config file
JoshuaSBrown Jul 26, 2020
f007e82
bump cmake version
JoshuaSBrown Jul 26, 2020
489e625
Fix small issues
JoshuaSBrown Jul 26, 2020
271ebee
Add missing files
JoshuaSBrown Jul 26, 2020
15bcb8f
Small fix
JoshuaSBrown Jul 26, 2020
eeb7263
Merge branch 'refactor' of github.com:JoshuaSBrown/QC_Tools into refa…
JoshuaSBrown Jul 26, 2020
70a204c
Fix merge conflicts
JoshuaSBrown Jul 26, 2020
781dc20
Move to unique_ptrs to help with Memory issues because of large EIgen…
JoshuaSBrown Jul 26, 2020
a1855d1
Move to c++17 standard
JoshuaSBrown Jul 31, 2020
c5e08ee
First step to refactor argumenent parsing
JoshuaSBrown Jul 31, 2020
e7b99c5
Replacing int and double properties with numeric
JoshuaSBrown Jul 31, 2020
49ae8b2
Refactored fileexist property
JoshuaSBrown Jul 31, 2020
77711c8
Minor correction
JoshuaSBrown Jul 31, 2020
61f9909
Major refactor of arguments and properties
JoshuaSBrown Aug 7, 2020
bf62ce0
Steps to refactor unit tests with properties
JoshuaSBrown Aug 7, 2020
0b71703
Small changes
JoshuaSBrown Sep 20, 2020
56ad101
Removed argument parser logic
JoshuaSBrown Dec 11, 2020
8f6bdb0
All tests working except io
JoshuaSBrown Dec 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "external/Catch2"]
path = external/Catch2
url = https://github.com/catchorg/Catch2.git
[submodule "external/MAMAP"]
path = external/MAMAP
url = https://github.com/JoshuaSBrown/MAMAP.git
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dist: xenial
addons:
apt:
update: true
packages: libeigen3-dev

language: cpp

Expand All @@ -17,6 +18,7 @@ jobs:
compiler: gcc
script: ./scripts/deploy.bash
apt:
packages: libeigen3-dev
packages: gcov
packages: lcov

Expand Down
168 changes: 90 additions & 78 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,120 +1,132 @@
cmake_minimum_required (VERSION 2.8)
project (calc_J)
cmake_minimum_required (VERSION 3.14)
project (catnip VERSION 2.0.0)

##############################################################################
# Defining options
##############################################################################
option(DOWNLOAD_TUTORIAL_FILES "Download tutorial files" OFF)
option(ENABLE_INTEGRATION_TESTS "Enable integration tests" OFF)
option(ENABLE_TESTS "Enable tests" OFF)
option(ENABLE_TESTS "Enable testing" OFF)
option(DOWNLOAD_TUTORIAL_FILES "Download tutorial files" ${ENABLE_TESTS})
option(ENABLE_INTEGRATION_TESTING "Enable integration tests" ${ENABLE_TESTS})
option(ENABLE_UNIT_TESTING "Enable unit tests" ${ENABLE_TESTS})
option(ENABLE_PROFILING "Enable profiling" OFF)
option(CODE_COVERAGE "Enable coverage reporting" OFF)

##############################################################################
# Override default options
##############################################################################
set(DOWNLOAD_TUTORIAL_FILES ${ENABLE_TESTS} CACHE STRING "Download tutorial files" FORCE)
set(ENABLE_INTEGRATION_TESTING ${ENABLE_TESTS} CACHE STRING "Enable integration tests" FORCE)
set(ENABLE_UNIT_TESTING ${ENABLE_TESTS} CACHE STRING "Enable unit tests" FORCE)

##############################################################################
# Defining settings
##############################################################################
set(calcJ_VERSION_MAJOR 1 )
set(calcJ_VERSION_MINOR 9 )
set(calcJ_YEAR_PUBLISHED 2018 )
set(calcJ_AUTHOR_SURNAME "\"Brown\"" )
set(calcJ_AUTHOR_INITIALS "\"J. S.\"" )
set(calcJ_TITLE "\"CATNIP\"")
set(calcJ_URL "\"https://github.com/JoshuaSBrown/QC_Tools\"" )
set(catnip_YEAR_PUBLISHED 2018 )
set(catnip_AUTHOR_SURNAME "\"Brown\"" )
set(catnip_AUTHOR_INITIALS "\"J. S.\"" )
set(catnip_TITLE "\"CATNIP\"")
set(catnip_URL "\"https://github.com/JoshuaSBrown/QC_Tools\"" )

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(COVERAGE_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
set(COMMON_LIBRARIES stdc++ m)
set(LOG_LEVEL 0 CACHE INT "Choose the log level" )
set(LOG_LEVEL 0 CACHE STRING "Choose the log level" )
# Prevents multiple file extensions from being appended one after the other
# important for using gcov .o.gcno or .cpp.gcno now will be .gcno
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++11 -pedantic -Werror")
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -Werror")

##############################################################################
# Check for Dependencies
##############################################################################

find_package(mamap REQUIRED)
if( NOT ${mamap_FOUND} )
include(${catnip_SOURCE_DIR}/cmake/InstallMAMAP.cmake)
else()
message(STATUS "found system installed mamap will not download")
endif()

##############################################################################
# Configuring header file with cmake variables
##############################################################################
# Configure header file to pass some of the CMake settings to the source code
configure_file(
"${PROJECT_SOURCE_DIR}/src/libcatnip/calcJconfig.hpp.in"
"${PROJECT_SOURCE_DIR}/src/libcatnip/calcJconfig.hpp"
"${catnip_SOURCE_DIR}/src/libcatnip/catnip_config.hpp.in"
"${catnip_SOURCE_DIR}/src/libcatnip/catnip_config.hpp"
)

##############################################################################
# Finding dependencies
##############################################################################
# Find bash it is important for testing using scripts
find_program (BASH_PROGRAM bash)
find_library (GCOV gcov)
#find_package (Eigen3 3.3 REQUIRED NO_MODULE)
#if (TARGET Eigen3::Eigen)
# message("-- Eigen found")
#endif(TARGET Eigen3::Eigen)
add_definitions(-DLOG_LEVEL=${LOG_LEVEL})

##############################################################################
# Setting up profiling
##############################################################################
if(${ENABLE_PROFILING})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
endif()
##############################################################################
# Setting up testing
##############################################################################
if(ENABLE_INTEGRATION_TESTS)
if(EXISTS "${PROJECT_SOURCE_DIR}/GAUSSIANFILES")
message("GAUSSIANFILES found will not download")
message("ENable tests ${ENABLE_TESTS} and integration ${ENABLE_INTEGRATION_TESTING}")
if(${ENABLE_INTEGRATION_TESTING})
if(EXISTS "${catnip_SOURCE_DIR}/GAUSSIANFILES")
message(STATUS "GAUSSIANFILES found will not download")
set(DOWNLOAD_TUTORIAL_FILES OFF)
else(EXISTS "${PROJECT_SOURCE_DIR}/GAUSSIANFILES")
message("GAUSSIANFILES not found will download")
set(DOWNLOAD_TUTORIAL_FILES ON)
endif(EXISTS "${PROJECT_SOURCE_DIR}/GAUSSIANFILES")
endif()

if(DOWNLOAD_TUTORIAL_FILES)
message("Downloading gaussian tutorial files")
execute_process(COMMAND ${PROJECT_SOURCE_DIR}/scripts/test_suite_install.bash "${PROJECT_SOURCE_DIR}" )
else(EXISTS "${catnip_SOURCE_DIR}/GAUSSIANFILES")
message(STATUS "GAUSSIANFILES not found will attempt to download")
include(${catnip_SOURCE_DIR}/cmake/InstallGdown.cmake)
endif(EXISTS "${catnip_SOURCE_DIR}/GAUSSIANFILES")
endif()

if(ENABLE_TESTS OR ENABLE_INTEGRATION_TESTS)
if(${ENABLE_UNIT_TESTING} OR ${ENABLE_INTEGRATION_TESTING})
find_package(Catch2 2.11.1)
if( NOT ${Catch2_FOUND} )
include(${catnip_SOURCE_DIR}/cmake/InstallCatch2.cmake)
else()
message(STATUS "found system installed Catch2 will not download")
endif()
enable_testing()
add_subdirectory("${PROJECT_SOURCE_DIR}/src/tests")
endif()
include(Catch)
include(ParseAndAddCatchTests)

if (ENABLE_INTEGRATION_TESTS)
file( COPY "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/90_unordered/90_pair.log"
DESTINATION "${PROJECT_BINARY_DIR}/GAUSSIANFILES/90_unordered")
file( COPY "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/90_unordered/90_pair.pun"
DESTINATION "${PROJECT_BINARY_DIR}/GAUSSIANFILES/90_unordered")

file( COPY "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/30_unordered/30_pair.pun"
DESTINATION "${PROJECT_BINARY_DIR}/GAUSSIANFILES/30_unordered")
file( COPY "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/30_unordered/ref.pun"
DESTINATION "${PROJECT_BINARY_DIR}/GAUSSIANFILES/30_unordered")
file( COPY "${PROJECT_SOURCE_DIR}/GAUSSIANFILES/30_unordered/30_2.pun"
DESTINATION "${PROJECT_BINARY_DIR}/GAUSSIANFILES/30_unordered")
endif()
if (${ENABLE_INTEGRATION_TESTING})
file( COPY "${catnip_SOURCE_DIR}/GAUSSIANFILES/90_unordered/90_pair.log"
DESTINATION "${catnip_BINARY_DIR}/GAUSSIANFILES/90_unordered")
file( COPY "${catnip_SOURCE_DIR}/GAUSSIANFILES/90_unordered/90_pair.pun"
DESTINATION "${catnip_BINARY_DIR}/GAUSSIANFILES/90_unordered")

if (ENABLE_TESTS)
file( COPY "${PROJECT_SOURCE_DIR}/src/tests/testfile.pun"
DESTINATION "${PROJECT_BINARY_DIR}/src/tests")
file( COPY "${PROJECT_SOURCE_DIR}/src/tests/testfile.log"
DESTINATION "${PROJECT_BINARY_DIR}/src/tests")
endif()
file( COPY "${catnip_SOURCE_DIR}/GAUSSIANFILES/30_unordered/30_pair.pun"
DESTINATION "${catnip_BINARY_DIR}/GAUSSIANFILES/30_unordered")
file( COPY "${catnip_SOURCE_DIR}/GAUSSIANFILES/30_unordered/ref.pun"
DESTINATION "${catnip_BINARY_DIR}/GAUSSIANFILES/30_unordered")
file( COPY "${catnip_SOURCE_DIR}/GAUSSIANFILES/30_unordered/30_2.pun"
DESTINATION "${catnip_BINARY_DIR}/GAUSSIANFILES/30_unordered")
endif()

if (${ENABLE_UNIT_TESTING})
file( COPY "${catnip_SOURCE_DIR}/src/tests/testfile.pun"
DESTINATION "${catnip_BINARY_DIR}/src/tests")
file( COPY "${catnip_SOURCE_DIR}/src/tests/testfile.log"
DESTINATION "${catnip_BINARY_DIR}/src/tests")
endif()

endif()
##############################################################################
# Compiling build tree/paths
##############################################################################
# Add the binary tree to the search path for include files
# so that we will find calcJconfig.hpp
include_directories("${PROJECT_BINARY_DIR}/src")
include_directories("${PROJECT_SOURCE_DIR}/src/libcatnip")
include_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/arguments/properties")
include_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/arguments")
include_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/file_readers")
include_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io")

link_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/arguments/properties")
link_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/arguments")
link_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io/file_readers")
link_directories("${PROJECT_SOURCE_DIR}/src/libcatnip/io")
link_directories("${PROJECT_SOURCE_DIR}/src/libcatnip")

add_subdirectory("${PROJECT_SOURCE_DIR}/src/libcatnip")

##############################################################################
# Creating calc_J and setting up code coverage if on
##############################################################################
add_executable(calc_J src/tools/main.cpp)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_link_libraries(calc_J gcov)
set_source_files_properties( src/tools/main.cpp PROPERTIES COMPILE_FLAGS ${COVERAGE_FLAGS})
endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_link_libraries(calc_J libcatnip ${COMMON_LIBRARIES})
install( TARGETS calc_J DESTINATION bin)
add_subdirectory("${catnip_SOURCE_DIR}/src")


11 changes: 11 additions & 0 deletions cmake/InstallCatch2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# If Catch2 is not found, instead use the git submodule
if (NOT EXISTS ${catnip_CURRENT_SOURCE_DIR}/external/Catch2/single_include)
# Unable to find the header files for Catch2 or they don't exist
message(STATUS "Downloading Catch2 submodule.")

# Clone the submodule
execute_process(COMMAND git submodule update --init --force -- external/Catch2 WORKING_DIRECTORY ${catnip_SOURCE_DIR})
endif()

add_subdirectory(${catnip_SOURCE_DIR}/external/Catch2)
list(APPEND CMAKE_MODULE_PATH "${catnip_SOURCE_DIR}/external/Catch2/contrib")
29 changes: 29 additions & 0 deletions cmake/InstallGdown.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

if(NOT EXISTS "${CMAKE_SOURCE_DIR}/GAUSSIANFILES")
find_program(GDOWN gdown ~/.local/bin)

if( NOT GDOWN)
find_program(PIP NAMES pip pip3 PATHS ~/.local/bin)
if( NOT PIP)
message(FATAL_ERROR "Unable to download tutorial files with gdown, tutorial"
"files are needed to run both the tutorials and the integration tests,"
"unable to locate pip to install gdown, please install pip, or install gdown"
"through some other means.")
else()
message("Pip is ")
execute_process(COMMAND ${PIP} "install" "--user" "--upgrade" "pip")
execute_process(COMMAND ${PIP} "install" "--user" "gdown" )
endif()
find_program(GDOWN gdown ~/.local/bin)

endif()

if( GDOWN )
find_program(UNZIP unzip)
execute_process(COMMAND ${GDOWN} https://drive.google.com/uc?id=1rCsj_jpMyE0S0cokFJDyBSA0aPNiIHNb WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
execute_process(COMMAND ${UNZIP} "GAUSSIANFILES.zip" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} )
execute_process(COMMAND rm "GAUSSIANFILES.zip" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
else()
message(FATAL_ERROR "Found pip, but still unable to install or find gdown")
endif()
endif()
10 changes: 10 additions & 0 deletions cmake/InstallMAMAP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# If Catch2 is not found, instead use the git submodule
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/MAMAP/include/mamap/argument_parser.hpp)
# Unable to find the header files for Catch2 or they don't exist
message(STATUS "Downloading MAMAP submodule.")

# Clone the submodule
execute_process(COMMAND git submodule update --init --force -- external/MAMAP WORKING_DIRECTORY ${catnip_SOURCE_DIR})
endif()

add_subdirectory(${catnip_SOURCE_DIR}/external/MAMAP)
1 change: 1 addition & 0 deletions external/Catch2
Submodule Catch2 added at 7f21cc
1 change: 1 addition & 0 deletions external/MAMAP
Submodule MAMAP added at 064104
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/libcatnip")
#add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/tools")
if(${ENABLE_UNIT_TESTING} OR ${ENABLE_INTEGRATION_TESTING})
message(STATUS "adding test directory")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/tests")
endif()


12 changes: 7 additions & 5 deletions src/libcatnip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

file(GLOB CATNIP_SOURCE_FILES
*.cpp
io/*.cpp
io/arguments/*.cpp
io/arguments/properties/*.cpp
io/file_readers/*.cpp)
io/io.cpp
string_support.cpp
io/file_readers/*.cpp
*.cpp)

add_library(libcatnip ${CATNIP_SOURCE_FILES})
set_property(TARGET libcatnip PROPERTY CXX_STANDARD 17)
target_include_directories(libcatnip PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(libcatnip PUBLIC mamap)
17 changes: 17 additions & 0 deletions src/libcatnip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Outline

Flow of the calc_J should follow as:

1. Read arguments
2. Assign files to atomic groups
3. Read atomic coordinates
4. Create group container
5. Assign group types
6. Create atom system
7. Check basis sets line up between components and complex
8. Load overlap matrices and molecular orbital coefficients
9. Create swap engine
10. Order matrices if needed
11. Generate Transfer integral complex
12. Calculate transfer integral

31 changes: 31 additions & 0 deletions src/libcatnip/atom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "atom.hpp"

namespace catnip {
double round(double N, double n)
{
int h;
double b, d, e, i, j, m, f;
b = N;

// Counting the no. of digits to the left of decimal point
// in the given no.
for (i = 0; b >= 1; ++i)
b = b / 10;

d = n - i;
b = N;
b = b * std::pow(10, d);
e = b + 0.5;
if ((float)e == (float)std::ceil(b)) {
f = (std::ceil(b));
h = f - 2;
if (h % 2 != 0) {
e = e - 1;
}
}
j = std::floor(e);
m = std::pow(10, d);
j = j / m;
return j;
}
}
Loading