LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-17-2023, 05:18 PM   #1
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
How can I compare floating point numbers in a Makefile?


Below is a basic Makefile where I am attempting to ascertain if I have a 'modern' g++ compiler that supports C++11. In the past, this worked fine, but now that I have version g++ 11.3.0, it does not.

Code:
ifndef CXX
CXX = g++
endif

GCC_VERSION := $(shell $(CXX) -dumpversion)
ifeq ($(shell expr $(GCC_VERSION) '>=' 4.5), 1)
CXXFLAGS  += -std=c++11
endif

foo:
    @echo "GCC_VERSION is: $(GCC_VERSION)"
    @echo "CXXFLAGS are  : $(CXXFLAGS)"
I've tried using 'test' in lieu of 'expr', but it only allows numeric (integer) values.

Is there a better way to ascertain if the compiler supports C++11?

Last edited by dwhitney67; 02-17-2023 at 06:12 PM.
 
Old 02-18-2023, 01:56 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,879

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
There are two ways.
1. split version string to major/minor version numbers and compare them one by one
2. use something which can do that, but actually these are not floating numbers (may contain two dots for example), so better to use the previous solution.
 
Old 02-18-2023, 09:14 AM   #3
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Original Poster
Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
I ended up relying on a combination of 'bc' (to perform a mathematical computation) and 'expr':

Code:
GCC_VERSION := $(shell $(CXX) -dumpversion)
CXX11_SUPPORTED := $(shell echo "$(GCC_VERSION) - 4.5 >= 0" | /usr/bin/bc -l)

ifeq ($(shell expr $(CXX11_SUPPORTED) '==' 1), 1)
    CXXFLAGS  += -std=c++11
endif
I wish there were something better than this kludge.
 
  


Reply

Tags
makefile



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
comparisions of floating point numbers bhatia.ankur8 Programming 3 09-13-2011 11:53 AM
LXer: The trouble with rounding floating point numbers LXer Syndicated Linux News 0 08-12-2006 01:54 PM
IEEE 754 floating point numbers dmail Programming 3 02-05-2006 05:10 AM
modulo of 2 floating point numbers? jenna_h Programming 6 09-24-2004 09:39 AM
floating point numbers in java spyghost Programming 8 09-06-2003 06:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration