Skip to content

Instantly share code, notes, and snippets.

@mrklein
Created October 6, 2014 15:23
Show Gist options
  • Save mrklein/2a2fb972b9b789883822 to your computer and use it in GitHub Desktop.
Save mrklein/2a2fb972b9b789883822 to your computer and use it in GitHub Desktop.
Arithmetics
leading_zero_strip = $(shell echo $$(echo $(1) | sed 's/^0*//'))
__plus = $(shell echo $$(($(1) + $(2))))
plus = $(call __plus,$(call leading_zero_strip,$(1)),$(call leading_zero_strip,$(2)))
__minus = $(shell echo $$(($(1) - $(2))))
minus = $(call __minus,$(call leading_zero_strip,$(1)),$(call leading_zero_strip,$(2)))
__mult = $(shell echo $$(($(1) * $(2))))
mult = $(call __mult,$(call leading_zero_strip,$(1)),$(call leading_zero_strip,$(2)))
__div = $(shell echo $$(($(1) / $(2))))
div = $(call __div,$(call leading_zero_strip,$(1)),$(call leading_zero_strip,$(2)))
A = 5
B = 10
C = 45
.DEFAULT: all
all:
@echo $(call plus,$(A),$(B))
@echo $(call minus,$(C),$(A))
@echo $(call mult,$(A),$(B))
@echo $(call div,$(C),$(A))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment