numeric_limits and valarray help with g++ and libstdc++

Joe Sinicropi jsinicroATsclrules.com
Thu Sep 16 10:36:00 GMT 1999


Hi,

Does enyone know how to make the following compile on Linux using the
g++ compiler and the libstdc++?


Makefile
---------------------------------------------------------------------

# Makefile for list11-2.cpp


##### MACROS #####

INCDIR = -I/usr/local/include/g++-3
-I/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.1/include
LIBDIR = /usr/local/lib/
XLIBS =
CXX   = g++
LIBS = $(LIBDIR) -lstdc++ -llimits
SOURCES  = list11-2.cpp
PROGS = mas


##### RULES #####


$(PROGS):$(SOURCES)
$(CXX) $(INCDIR) $(CFLAGS) $< $(LIBS) -o $@



##### TARGETS #####

default: $(PROGS)

clean:
 -rm *.o *~

realclean:
 -rm $(PROGS)
 -rm *.o *~


---------------------------------------------------------------------

Listing
---------------------------------------------------------------------
// Listing 11-2
// This program uses vector addition
// and vector substraction on valarray
// objects with the help of the numeric_limits
// class.


#include <valarray>
#include <iostream>
#include <limits>


using namespace std;

int main(int argc, char **argv)
{
   numeric_limits<double> Real;
   valarray<double> X(Real.max(),100000);
   valarray<double> Y(X);
   valarray<double> Z(0.0,100000);
   Y = Y - Real.epsilon();
   Y = Y + Real.epsilon();
   Z = X - Y;
   if(Z.sum() == 0){
      cout << "The Math Stuff Worked!" << endl;
   }
   else{
         cerr << "OH oh!" << endl;

   }
   return 0;
}
-----------------------------------------------------------------


Thanks,

Joe Sinicropi



More information about the Gcc-help mailing list