diff --git a/c/printf_round/Makefile b/c/printf_round/Makefile new file mode 100644 index 0000000..edf5c7f --- /dev/null +++ b/c/printf_round/Makefile @@ -0,0 +1,102 @@ +# This file is generated with smake.sh. +# You can use this make file with instruction make to +# use one of build mode: debug, profile, develop, release. +# No need to call make clean if You make with other mode, +# because the Makefile containes rules for automatically clean. +# Some usage examples: +# make # default mode is debug +# CFLAGS="-O2 -march=core2 -mtune=core2 --msse4.1 mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,-ass-needed" make mode=develop +# CFLAGS="-O2 -march=amdfam10 -mtune=amdfam10 -msse4a --mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=profile +# CFLAGS="-O2 -march=k6-2 -mtune=k6-2 -m3dnow --mfpmath=387 -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=release +# Report bugs to + +#_________________________________ +# ENVIRONMENT | +#________________________________| +CC=cc +CXX=c++ +LIBRARIES= +TARGET0=printf_round +TARGET= $(TARGET0) +INCLUDE1=$(HOME)/projects/include +INCLUDE2=/usr/local/include +INCLUDE=-I$(INCLUDE1) -I$(INCLUDE2) + +#________________________________________ +# BUILD SCRIPT (don't change) | +#_______________________________________| +ifeq ($(mode),) + mode = debug +endif +ifeq ($(mode),debug) + CFLAGS := -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion $(CFLAGS) + LDFLAGS := $(LDFLAGS) +endif +ifeq ($(mode),profile) + CFLAGS := -O0 -g -p -ftest-coverage -Wcoverage-mismatch $(CFLAGS) + LDFLAGS := -g -p $(LDFLAGS) +endif +ifeq ($(mode),develop) + CFLAGS := -O2 -g $(CFLAGS) + LDFLAGS := -O1 $(LDFLAGS) +endif +ifeq ($(mode),release) + CFLAGS := -O2 $(CFLAGS) + LDFLAGS := -O1 $(LDFLAGS) +endif + +CFLAGS += -Wall +LDFLAGS += -Wall $(LIBRARIES) + +all: change_make_options $(TARGET) + +ifneq ($(mode),debug) +ifneq ($(mode),profile) +ifneq ($(mode),develop) +ifneq ($(mode),release) + @echo "Invalid build mode." + @echo "Please use 'make mode=release', 'make mode=develop', 'make mode=profile' or 'make mode=debug'" + @exit 1 +endif +endif +endif +endif + @echo ".........................." + @echo "Building on "$(mode)" mode " + @echo "CFLAGS=$(CFLAGS)" + @echo "LDFLAGS=$(LDFLAGS)" + @echo ".........................." + +OLD_BUILD_MODE=$(shell grep ^MODE make_options.out 2>/dev/null | sed 's~^MODE=~~') +OLD_BUILD_CFLAGS=$(shell grep ^CFLAGS make_options.out 2>/dev/null | sed 's~^CFLAGS=~~') +OLD_BUILD_LDFLAGS=$(shell grep ^LDFLAGS make_options.out 2>/dev/null | sed 's~^LDFLAGS=~~') +change_make_options: +ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS)) + @echo CLEANING... + @make clean &>/dev/null + @echo "MODE=$(mode)" > make_options.out + @echo "CFLAGS=$(CFLAGS)" >> make_options.out + @echo "LDFLAGS=$(LDFLAGS)" >> make_options.out +endif + +%.o : + $(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $< + +clean: + $(RM) *.o *.out callgrind.out.* *.gcno $(TARGET) + +.PHONY: all change_make_options clean + +#_________________________________ +# R U L E S | +#________________________________| +target_objs0 = \ + printf_round.o + +$(TARGET0): $(target_objs0) + $(CC) $(LDFLAGS) -o $@ $(target_objs0) + + +printf_round.o: \ + printf_round.c + diff --git a/c/printf_round/printf_round.c b/c/printf_round/printf_round.c new file mode 100644 index 0000000..1d38fe2 --- /dev/null +++ b/c/printf_round/printf_round.c @@ -0,0 +1,9 @@ +#include + +int main(void) +{ + long double tmp = 4.1 * 0.25 - 1; + tmp = 0.025; + printf("%.20lf\n", tmp); +} + diff --git a/cpp/list_sort/Makefile b/cpp/list_sort/Makefile new file mode 100644 index 0000000..dcdc77f --- /dev/null +++ b/cpp/list_sort/Makefile @@ -0,0 +1,102 @@ +# This file is generated with smake.sh. +# You can use this make file with instruction make to +# use one of build mode: debug, profile, develop, release. +# No need to call make clean if You make with other mode, +# because the Makefile containes rules for automatically clean. +# Some usage examples: +# make # default mode is debug +# CFLAGS="-O2 -march=core2 -mtune=core2 --msse4.1 mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,-ass-needed" make mode=develop +# CFLAGS="-O2 -march=amdfam10 -mtune=amdfam10 -msse4a --mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=profile +# CFLAGS="-O2 -march=k6-2 -mtune=k6-2 -m3dnow --mfpmath=387 -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=release +# Report bugs to + +#_________________________________ +# ENVIRONMENT | +#________________________________| +CC=cc +CXX=c++ +LIBRARIES=-lstdc++ +TARGET0=list_sort +TARGET= $(TARGET0) +INCLUDE1=$(HOME)/projects/include +INCLUDE2=/usr/local/include +INCLUDE=-I$(INCLUDE1) -I$(INCLUDE2) + +#________________________________________ +# BUILD SCRIPT (don't change) | +#_______________________________________| +ifeq ($(mode),) + mode = debug +endif +ifeq ($(mode),debug) + CFLAGS := -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion $(CFLAGS) + LDFLAGS := $(LDFLAGS) +endif +ifeq ($(mode),profile) + CFLAGS := -O0 -g -p -ftest-coverage -Wcoverage-mismatch $(CFLAGS) + LDFLAGS := -g -p $(LDFLAGS) +endif +ifeq ($(mode),develop) + CFLAGS := -O2 -g $(CFLAGS) + LDFLAGS := -O1 $(LDFLAGS) +endif +ifeq ($(mode),release) + CFLAGS := -O2 $(CFLAGS) + LDFLAGS := -O1 $(LDFLAGS) +endif + +CFLAGS += -Wall +LDFLAGS += -Wall $(LIBRARIES) + +all: change_make_options $(TARGET) + +ifneq ($(mode),debug) +ifneq ($(mode),profile) +ifneq ($(mode),develop) +ifneq ($(mode),release) + @echo "Invalid build mode." + @echo "Please use 'make mode=release', 'make mode=develop', 'make mode=profile' or 'make mode=debug'" + @exit 1 +endif +endif +endif +endif + @echo ".........................." + @echo "Building on "$(mode)" mode " + @echo "CFLAGS=$(CFLAGS)" + @echo "LDFLAGS=$(LDFLAGS)" + @echo ".........................." + +OLD_BUILD_MODE=$(shell grep ^MODE make_options.out 2>/dev/null | sed 's~^MODE=~~') +OLD_BUILD_CFLAGS=$(shell grep ^CFLAGS make_options.out 2>/dev/null | sed 's~^CFLAGS=~~') +OLD_BUILD_LDFLAGS=$(shell grep ^LDFLAGS make_options.out 2>/dev/null | sed 's~^LDFLAGS=~~') +change_make_options: +ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS)) + @echo CLEANING... + @make clean &>/dev/null + @echo "MODE=$(mode)" > make_options.out + @echo "CFLAGS=$(CFLAGS)" >> make_options.out + @echo "LDFLAGS=$(LDFLAGS)" >> make_options.out +endif + +%.o : + $(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $< + +clean: + $(RM) *.o *.out callgrind.out.* *.gcno $(TARGET) + +.PHONY: all change_make_options clean + +#_________________________________ +# R U L E S | +#________________________________| +target_objs0 = \ + list_sort.o + +$(TARGET0): $(target_objs0) + $(CC) $(LDFLAGS) -o $@ $(target_objs0) + + +list_sort.o: \ + list_sort.cpp + diff --git a/cpp/list_sort/list_sort.cpp b/cpp/list_sort/list_sort.cpp new file mode 100644 index 0000000..502ed5b --- /dev/null +++ b/cpp/list_sort/list_sort.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +bool str_num_cmp(const std::string& s1, const std::string& s2) +{ + return atoi(s1.c_str()) < atoi(s2.c_str()) ? true : false; +} + +void show_list(const std::list lst) +{ + for (std::list::const_iterator it = lst.begin(); + it != lst.end(); + it++) + std::cout << it->c_str() << " " << std::endl; +} + +int main(void) +{ + char *arr[] = { + "324", "2133", "938", "202", "199", "200" + + }; + std::list lst; + + for (size_t i = 0, max_i = sizeof(arr) / sizeof(char *); i < max_i; i++) + lst.push_back(arr[i]); + + std::cout << "Not sorted:" << std::endl; + show_list(lst); + + lst.sort(); + + std::cout << "Standart sorted:" << std::endl; + show_list(lst); + + lst.sort(str_num_cmp); + + std::cout << "str_num_cmp sorted:" << std::endl; + show_list(lst); + + return EXIT_SUCCESS; +} +