Skip to content

Instantly share code, notes, and snippets.

@Dimon70007
Forked from pushandplay/Makefile Tricks
Created August 18, 2021 10:40
Show Gist options
  • Save Dimon70007/7c936bcdfcc6ae03652e5baa64e0d58f to your computer and use it in GitHub Desktop.
Save Dimon70007/7c936bcdfcc6ae03652e5baa64e0d58f to your computer and use it in GitHub Desktop.
Makefile Tricks: Arithmetic – Addition, Subtraction, Multiplication, Division, Modulo, Comparison
NUMBER1 := 10
NUMBER2 := 5
#Addition
ADD := $(shell echo ${NUMBER1}+${NUMBER2} | bc)
#Subtraction
SUBTRACT := $(shell echo ${NUMBER1}-${NUMBER2} | bc)
#Multiplication
MULTIPLY := $(shell echo ${NUMBER1}*${NUMBER2} | bc)
#Division
DIVIDE := $(shell echo ${NUMBER1}/${NUMBER2} | bc)
#Division (Floating Point)
DIVIDEF := $(shell echo "scale=3; ${NUMBER2}/${NUMBER1}" | bc)
#Modulo
MODULO := $(shell echo ${NUMBER1}%${NUMBER2} | bc)
#Comparison Greater Than
COMPARISON1 := $(shell echo ${NUMBER1}\>=${NUMBER2} | bc)
#Comparison Smaller Than
COMPARISON2 := $(shell echo ${NUMBER2}\<=${NUMBER2} | bc)
all:
@echo Addition ${ADD}
@echo Subtraction ${SUBTRACT}
@echo Multiplication ${MULTIPLY}
@echo Division ${DIVIDE}
@echo Division - Floating Point ${DIVIDEF}
@echo Modulo ${MODULO}
@echo Comparison Greater Than ${COMPARISON1}
@echo Comparison Smaller Than ${COMPARISON2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment