[git commit] valarray: bunch of fixes
Bernhard Reutner-Fischer
rep.dot.nop at gmail.com
Fri May 25 20:44:28 UTC 2012
commit: http://git.uclibc.org/uClibc++/commit/?id=53ae6c38a7a440aed9d74067c1814e58e9e16b79
branch: http://git.uclibc.org/uClibc++/commit/?id=refs/heads/master
Fix operator=(const valarray<T>&) DR 630
Adjust constness of operator[](size_t)
Properly implement class member valarray<bool> operator!()
Fix operator|= (const T&) to or, not not
Fix both shift() and cshift() for any overrun and +- offsets
Fix slice_array& operator=(const slice_array&) to return properly
Adjust class gslice default constructor DR 543
Fix valarray<bool> operator>(const T&, const valarray<T>&)
Return the result of all algo
Fix copy'n paster error in atan2() inner fn call
Fix pow (const T& const valarray<T>&)
Later versions add .swap, prepare for that.
Dump additional observations to TODO
Unnoted: satisfy gcc/libstdc++/testsuite/26_numerics/valarray/dr543.cc really
Unnoted: TR1/2 audit? Check against current boost? ;)
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
ChangeLog | 11 +++
TODO | 2 +
include/valarray | 88 ++++++++++++++-----
tests/Makefile | 10 ++-
tests/testoutput/valarraytest.good | 74 +++++++++++++++-
tests/valarraytest.cpp | 170 +++++++++++++++++++++++++++++++++--
6 files changed, 318 insertions(+), 37 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4887d09..7edb613 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,15 @@
0.2.4
+- valarray: Fix operator=(const valarray<T>&) DR 630
+- valarray: Adjust constness of operator[](size_t)
+- valarray: Properly implement class member valarray<bool> operator!()
+- valarray: Fix operator|= (const T&) to or, not not
+- valarray: Fix both shift() and cshift() for any overrun and +- offsets
+- valarray: Fix slice_array& operator=(const slice_array&) to return properly
+- valarray: Adjust class gslice default constructor DR 543
+- valarray: Fix valarray<bool> operator>(const T&, const valarray<T>&)
+- valarray: Return the result of all algo
+- valarray: Fix copy'n paster error in atan2() inner fn call
+- valarray: Fix pow (const T& const valarray<T>&)
- istream: fix readin<traits, char, bool>
0.2.3
diff --git a/TODO b/TODO
index 095bf6d..a1a7e20 100644
--- a/TODO
+++ b/TODO
@@ -22,3 +22,5 @@ Clean up istream code so that a lot of the checking for stuff is put into
Find out why utilities pair operator= isn't working correctly
+
+slice_array: remove fill(), constify operator=
diff --git a/include/valarray b/include/valarray
index 983d458..09d929c 100644
--- a/include/valarray
+++ b/include/valarray
@@ -113,7 +113,12 @@ namespace std{
}
valarray<T>& operator=(const valarray<T>& v){
- for(size_t i =0; i< length; ++i){
+ if (length != v.length) { // DR 630
+ delete [] data;
+ length = v.length;
+ data = new T[length];
+ }
+ for (size_t i = 0; i < length; ++i) {
data[i] = v.data[i];
}
return *this;
@@ -134,7 +139,7 @@ namespace std{
valarray<T>& operator=(const mask_array<T>&);
valarray<T>& operator=(const indirect_array<T>&);
- T operator[](size_t t) const{
+ const T& operator[](size_t t) const{
return data[t];
}
T& operator[](size_t t){
@@ -184,10 +189,10 @@ namespace std{
}
return retval;
}
- valarray<T> operator!() const{
- valarray<T> retval(length);
- for(size_t i = 0; i< length ; ++i){
- retval.data[i] = !data[i];
+ valarray<bool> operator!() const{
+ valarray<bool> retval(length);
+ for (size_t i = 0; i < length ; ++i){
+ retval[i] = !data[i];
}
return retval;
}
@@ -235,7 +240,7 @@ namespace std{
}
valarray<T>& operator|= (const T& t){
for(size_t i=0;i<length; ++i){
- data[i] != t;
+ data[i] |= t;
}
return *this;
}
@@ -311,7 +316,12 @@ namespace std{
}
return *this;
}
-
+#if 0
+ void swap(valarray& other) noexcept {
+ std::swap(length, other.length);
+ std::swap(data, other.data);
+ }
+#endif
size_t size() const{
return length;
}
@@ -346,17 +356,33 @@ namespace std{
valarray<T> shift (int n) const{
valarray<T> retval(length);
- for(size_t i = 0; i < length ; ++i){
- if(i + n > 0 && i + n < length){
- retval.data[i] = data[i + n];
- }
+ if (n < 0) {
+ if (-size_t(n) > length)
+ n = -int(length);
+ } else {
+ if (size_t(n) > length)
+ n = int(length);
+ }
+ for (size_t i = 0; i < length ; ++i) {
+ if ((n + i) < length)
+ retval.data[i] = data[n + i];
}
return retval;
}
valarray<T> cshift(int n) const{
valarray<T> retval(length);
- for(size_t i = 0; i < length ; ++i){
- retval.data[i] = data[ (i + n) % length ];
+ if (length == 0)
+ return retval;
+ if (n < 0) {
+ if (-size_t(n) > length)
+ n = -int(-size_t(n) % length);
+ n = length + n;
+ } else {
+ if (size_t(n) > length)
+ n = int(size_t(n) % length);
+ }
+ for (size_t i = 0; i < length ; ++i){
+ retval.data[i] = data[(n + i) % length];
}
return retval;
}
@@ -471,6 +497,7 @@ namespace std{
slice_array& operator=(const slice_array& sa){
array = sa.array;
s = sa.s;
+ return *this;
}
private:
@@ -486,7 +513,7 @@ namespace std{
valarray<size_t> str;
public:
- gslice() : sta(0) { }
+ gslice() : sta(0), siz(), str() { } // DR 543
gslice(size_t s, const valarray<size_t>& l, const valarray<size_t>& d)
: sta(s), siz(l), str(d) { }
@@ -598,7 +625,7 @@ namespace std{
}
template<class T> valarray<T> operator- (const valarray<T>& lhs, const T& rhs){
valarray<T> retval(lhs);
- retval-= rhs;
+ retval -= rhs;
return retval;
}
template<class T> valarray<T> operator- (const T& lhs, const valarray<T>& rhs){
@@ -802,7 +829,7 @@ namespace std{
}
return retval;
}
- template<class T> valarray<bool> operator> (const T& rhs, const valarray<T>& lhs){
+ template<class T> valarray<bool> operator> (const T& lhs, const valarray<T>& rhs){
valarray<bool> retval(rhs.size());
for(size_t i = 0; i <retval.size(); ++i){
retval[i] = lhs > rhs[i];
@@ -873,122 +900,141 @@ namespace std{
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = abs(x[i]);
}
+ return retval;
}
template<class T> valarray<T> acos (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = acos(x[i]);
}
+ return retval;
}
template<class T> valarray<T> asin (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = asin(x[i]);
}
+ return retval;
}
template<class T> valarray<T> atan (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = atan(x[i]);
}
+ return retval;
}
template<class T> valarray<T> atan2(const valarray<T>& y, const valarray<T>& x){
valarray<T> retval(y.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = atan2(y[i], x[i]);
}
+ return retval;
}
template<class T> valarray<T> atan2(const valarray<T>& y, const T& x){
valarray<T> retval(y.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = atan2(y[i], x);
}
+ return retval;
}
template<class T> valarray<T> atan2(const T& y, const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
- retval[i] = abs(y, x[i]);
+ retval[i] = atan2(y, x[i]);
}
+ return retval;
}
template<class T> valarray<T> cos (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = cos(x[i]);
}
+ return retval;
}
template<class T> valarray<T> cosh (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = cosh(x[i]);
}
+ return retval;
}
template<class T> valarray<T> exp (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = exp(x[i]);
}
+ return retval;
}
template<class T> valarray<T> log (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = log(x[i]);
}
+ return retval;
}
template<class T> valarray<T> log10(const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = log10(x[i]);
}
+ return retval;
}
- template<class T> valarray<T> pow (const valarray<T>& x, const valarray<T>& y){
+ template<class T> valarray<T> pow (const valarray<T>& x, const valarray<T>& y){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = pow(x[i], y[i]);
}
+ return retval;
}
template<class T> valarray<T> pow (const valarray<T>& x, const T& y){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = pow(x[i], y);
}
+ return retval;
}
template<class T> valarray<T> pow (const T& x, const valarray<T>& y){
- valarray<T> retval(x.size());
+ valarray<T> retval(y.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = pow(x, y[i]);
}
+ return retval;
}
template<class T> valarray<T> sin (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = sin(x[i]);
}
+ return retval;
}
template<class T> valarray<T> sinh (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = sinh(x[i]);
}
+ return retval;
}
template<class T> valarray<T> sqrt (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = sqrt(x[i]);
}
+ return retval;
}
template<class T> valarray<T> tan (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = tan(x[i]);
}
+ return retval;
}
template<class T> valarray<T> tanh (const valarray<T>& x){
valarray<T> retval(x.size());
for(size_t i = 0; i < retval.size(); ++i){
retval[i] = tanh(x[i]);
}
+ return retval;
}
-
}
#pragma GCC visibility pop
diff --git a/tests/Makefile b/tests/Makefile
index 06f158e..3ed8a26 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -26,6 +26,8 @@ ALLBIN := $(patsubst %.cpp,%, $(TEST_SRCS))
OLDBIN := $(patsubst %.cpp,%-old, $(TEST_SRCS))
+LDFLAGS-valarraytest := -lm
+
ifeq ($(DODEBUG),y)
all: $(ALLBIN) $(OLDBIN)
else
@@ -41,16 +43,16 @@ test: all
$(MAKE) -C testoutput test
$(ALLBIN): $(EXOBJS) $(UTILITY_OBJS)
- $(WR_CXX) $(LDFLAGS) $(UTILITY_OBJS) -o $@ $@.o
+ $(WR_CXX) $(LDFLAGS) $(UTILITY_OBJS) -o $@ $@.o $(LDFLAGS-$(notdir $(@)))
$(OLDBIN): $(OLDOBJS) $(OLDUTILITY_OBJS)
- $(HOSTCXX) $(LDFLAGS) $(UTILITY_OBJS) -o $@ $@.o
+ $(HOSTCXX) $(LDFLAGS) $(UTILITY_OBJS) -o $@ $@.o $(LDFLAGS-$(notdir $(@)))
$(EXOBJS): %.o : %.cpp
- $(WR_CXX) $(CXXFLAGS) -o $@ -c $<
+ $(WR_CXX) $(CXXFLAGS) $(CXXFLAGS-$(notdir $(*))) -o $@ -c $<
$(OLDOBJS): %-old.o : %.cpp
- $(HOSTCXX) $(CXXFLAGS) -o $@ -c $<
+ $(HOSTCXX) $(CXXFLAGS) $(CXXFLAGS-$(notdir $(*))) -o $@ -c $<
$(UTILITY_OBJS): %.o : %.cpp
$(WR_CXX) $(CXXFLAGS) -o $@ -c $<
diff --git a/tests/testoutput/valarraytest.good b/tests/testoutput/valarraytest.good
index d574e68..2468c62 100644
--- a/tests/testoutput/valarraytest.good
+++ b/tests/testoutput/valarraytest.good
@@ -1,2 +1,72 @@
-Value of valarray:0 1 2 3 4 5 6 7 8 9
-Value of slice_array:1 3 5 7 9
+Value of valarray<int> a: 0 1 2 3 4 5 6 7 8 9
+Value of slice_array: 1 3 5 7 9
+
+valarray operators
+Value of -a: 0 -1 -2 -3 -4 -5 -6 -7 -8 -9
+Value of +a: 0 1 2 3 4 5 6 7 8 9
+Value of ~a: -1 -2 -3 -4 -5 -6 -7 -8 -9 -10
+valarray<bool> = !a: 1 0 0 0 0 0 0 0 0 0
+(valarray<bool> = !valarray<int>).max() = 1
+(valarray<bool> = !valarray<int>).min() = 0
+
+valarray algo
+valarray.max() = 9
+Result of abs(a): 0 1 2 3 4 5 6 7 8 9
+Result of acos(d): 1.5708 0 nan nan nan nan nan nan nan nan
+Result of acos(f): 1.5708 nan nan nan nan nan nan nan nan nan
+Result of acos(ld): 1.5708 0 nan nan nan nan nan nan nan nan
+Result of asin(d): 0 1.5708 nan nan nan nan nan nan nan nan
+Result of asin(f): 0 nan nan nan nan nan nan nan nan nan
+Result of asin(ld): 0 1.5708 nan nan nan nan nan nan nan nan
+Result of atan(d): 0 0.785398 1.10715 1.24905 1.32582 1.3734 1.40565 1.4289 1.44644 1.46014
+Result of atan(f): 0 0.832981 1.14417 1.27656 1.34732 1.39094 1.42042 1.44165 1.45765 1.47013
+Result of atan(ld): 0 0.785398 1.57078 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708
+Result of atan2(d, d): 0 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398
+Result of atan2(type, d): 0 0 0 0 0 0 0 0 0 0
+Result of atan2(d, type): 0 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708
+Result of atan2(f, f): 0 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398
+Result of atan2(type, f): 0 0 0 0 0 0 0 0 0 0
+Result of atan2(f, type): 0 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708
+Result of atan2(ld, ld): 0 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398 0.785398
+Result of atan2(type, ld): 0 0 0 0 0 0 0 0 0 0
+Result of atan2(ld, type): 0 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708
+Result of cos(d): 1 0.540302 -0.416147 -0.989992 -0.653644 0.283662 0.96017 0.753902 -0.1455 -0.91113
+Result of cos(f): 1 0.453596 -0.588501 -0.98748 -0.307333 0.70867 0.950233 0.153374 -0.811093 -0.889191
+Result of cos(ld): 1 0.540302 -0.721835 -0.90761 -0.886887 0.915809 0.628683 0.0376966 0.99158 0.817215
+Result of cosh(d): 1 1.54308 3.7622 10.0677 27.3082 74.2099 201.716 548.317 1490.48 4051.54
+Result of cosh(f): 1 1.66852 4.56791 13.5748 40.7316 122.348 367.548 1104.17 3317.12 9965.18
+Result of cosh(ld): 1 1.54308 inf inf inf inf inf inf inf inf
+Result of exp(d): 1 2.71828 7.38906 20.0855 54.5982 148.413 403.429 1096.63 2980.96 8103.08
+Result of exp(f): 1 3.00417 9.02501 27.1126 81.4509 244.692 735.095 2208.35 6634.25 19930.4
+Result of exp(ld): 1 2.71828 inf inf inf inf inf inf inf inf
+Result of log(d): -inf 0 0.693147 1.09861 1.38629 1.60944 1.79176 1.94591 2.07944 2.19722
+Result of log(f): -inf 0.0953102 0.788457 1.19392 1.4816 1.70475 1.88707 2.04122 2.17475 2.29253
+Result of log(ld): -inf 0 11.0904 17.5778 22.1807 25.751 28.6682 31.1346 33.2711 35.1556
+Result of log10(d): -inf 0 0.30103 0.477121 0.60206 0.69897 0.778151 0.845098 0.90309 0.954243
+Result of log10(f): -inf 0.0413927 0.342423 0.518514 0.643453 0.740363 0.819544 0.886491 0.944483 0.995635
+Result of log10(ld): -inf 0 4.81648 7.63394 9.63296 11.1835 12.4504 13.5216 14.4494 15.2679
+Result of pow(d, d): 1 1 4 27 256 3125 46656 823543 1.67772e+07 3.8742e+08
+Result of pow(type, d): 1 0 0 0 0 0 0 0 0 0
+Result of pow(d, type): 1 1 1 1 1 1 1 1 1 1
+Result of pow(f, f): 1 1.11053 5.6667 51.4157 677.941 11803.1 256442 6.69851e+06 2.04856e+08 7.19098e+09
+Result of pow(type, f): 1 0 0 0 0 0 0 0 0 0
+Result of pow(f, type): 1 1 1 1 1 1 1 1 1 1
+Result of pow(ld, ld): 1 1 inf inf inf inf inf inf inf inf
+Result of pow(type, ld): 1 0 0 0 0 0 0 0 0 0
+Result of pow(ld, type): 1 1 1 1 1 1 1 1 1 1
+Result of sin(d): 0 0.841471 0.909297 0.14112 -0.756802 -0.958924 -0.279415 0.656987 0.989358 0.412118
+Result of sin(f): 0 0.891207 0.808496 -0.157746 -0.951602 -0.70554 0.311541 0.988168 0.584917 -0.457536
+Result of sin(ld): 0 0.841471 0.692065 0.419814 -0.461987 -0.401613 0.777662 -0.999289 0.129496 -0.576333
+Result of sinh(d): 0 1.1752 3.62686 10.0179 27.2899 74.2032 201.713 548.316 1490.48 4051.54
+Result of sinh(f): 0 1.33565 4.45711 13.5379 40.7193 122.344 367.547 1104.17 3317.12 9965.18
+Result of sinh(ld): 0 1.1752 inf inf inf inf inf inf inf inf
+Result of sqrt(d): 0 1 1.41421 1.73205 2 2.23607 2.44949 2.64575 2.82843 3
+Result of sqrt(f): 0 1.04881 1.48324 1.81659 2.09762 2.34521 2.56905 2.77489 2.96648 3.14643
+Result of sqrt(ld): 0 1 256 6561 65536 390625 1.67962e+06 5.7648e+06 1.67772e+07 4.30467e+07
+Result of tan(d): 0 1.55741 -2.18504 -0.142547 1.15782 -3.38052 -0.291006 0.871448 -6.79971 -0.452316
+Result of tan(f): 0 1.96476 -1.37382 0.159746 3.09632 -0.995584 0.327858 6.44286 -0.721147 0.514552
+Result of tan(ld): 0 1.55741 -0.958759 -0.462548 0.520908 -0.438534 1.23697 -26.5087 0.130596 -0.705241
+Result of tanh(d): 0 0.761594 0.964028 0.995055 0.999329 0.999909 0.999988 0.999998 1 1
+Result of tanh(f): 0 0.800499 0.975743 0.997283 0.999699 0.999967 0.999996 1 1 1
+Result of tanh(ld): 0 0.761594 1 1 1 1 1 1 1 1
+
diff --git a/tests/valarraytest.cpp b/tests/valarraytest.cpp
index 9e5c2e4..ec5503b 100644
--- a/tests/valarraytest.cpp
+++ b/tests/valarraytest.cpp
@@ -1,9 +1,56 @@
#include <iostream>
#include <valarray>
+bool check_array(std::valarray<int>& a, int b[]) {
+ for (size_t i = 0; i < a.size(); i++)
+ if (a[i] != b[i]) {
+ std::cout << "[" << i << "] "
+ << a[i] << " != " << b[i] << std::endl;
+ return false;
+ }
+ return true;
+}
+
+void print_array(std::string s, std::valarray<bool>& a) {
+ std::cout << s;
+ for (size_t i = 0; i < a.size(); ++i){
+ std::cout << " " << a[i];
+ }
+ std::cout << std::endl;
+}
+void print_array(std::string s, std::valarray<int>& a) {
+ std::cout << s;
+ for (size_t i = 0; i < a.size(); ++i){
+ std::cout << " " << a[i];
+ }
+ std::cout << std::endl;
+}
+void print_array(std::string s, std::valarray<double>& a) {
+ std::cout << s;
+ for (size_t i = 0; i < a.size(); ++i){
+ std::cout << " " << a[i];
+ }
+ std::cout << std::endl;
+}
+void print_array(std::string s, std::valarray<float>& a) {
+ std::cout << s;
+ for (size_t i = 0; i < a.size(); ++i){
+ std::cout << " " << a[i];
+ }
+ std::cout << std::endl;
+}
+#if defined __UCLIBCXX_HAS_LONG_DOUBLE__ || defined _GLIBCXX_USE_C99_MATH_TR1
+void print_array(std::string s, std::valarray<long double>& a) {
+ std::cout << s;
+ for (size_t i = 0; i < a.size(); ++i){
+ std::cout << " " << a[i];
+ }
+ std::cout << std::endl;
+}
+#endif
int main(){
-
+
std::valarray<int> a(10);
a[0] = 0;
a[1] = 1;
@@ -16,19 +63,122 @@ int main(){
a[8] = 8;
a[9] = 9;
- std::cout << "Value of valarray:" ;
- for(size_t i = 0; i < a.size(); ++i){
- std::cout << a[i] << " ";
- }
- std::cout << std::endl;
+ print_array("Value of valarray<int> a:", a);
std::valarray<int> sl(a[std::slice(1, 5, 2)]);
- std::cout << "Value of slice_array:" ;
- for(size_t i = 0; i < sl.size(); ++i){
- std::cout << sl[i] << " ";
- }
+ print_array("Value of slice_array:", sl);
+
+ std::cout << std::endl;
+ std::cout << "valarray operators" << std::endl;
+ std::valarray<int> c = -a;
+ print_array("Value of -a:", c);
+ c = +a;
+ print_array("Value of +a:", c);
+ c = ~a;
+ print_array("Value of ~a:", c);
+
+ std::valarray<bool> b = !a;
+ print_array("valarray<bool> = !a:", b);
+ std::cout << "(valarray<bool> = !valarray<int>).max() = " << b.max() << std::endl;
+ std::cout << "(valarray<bool> = !valarray<int>).min() = " << b.min() << std::endl;
+
std::cout << std::endl;
+ std::cout << "valarray algo" << std::endl;
+ std::cout << "valarray.max() = " << a.max() << std::endl;
+ c = abs(a);
+ print_array("Result of abs(a):", c);
+
+ double dd;
+ float ff;
+ std::valarray<double> d(10), ret_d(10);
+ std::valarray<float> f(10), ret_f(10);
+ d[0] = 0;
+ d[1] = 1;
+ d[2] = 2;
+ d[3] = 3;
+ d[4] = 4;
+ d[5] = 5;
+ d[6] = 6;
+ d[7] = 7;
+ d[8] = 8;
+ d[9] = 9;
+ f[0] = 0.0;
+ f[1] = 1.1;
+ f[2] = 2.2;
+ f[3] = 3.3;
+ f[4] = 4.4;
+ f[5] = 5.5;
+ f[6] = 6.6;
+ f[7] = 7.7;
+ f[8] = 8.8;
+ f[9] = 9.9;
+#if defined __UCLIBCXX_HAS_LONG_DOUBLE__ || defined _GLIBCXX_USE_C99_MATH_TR1
+ long double ldld;
+ std::valarray<long double> ld(10), ret_ld(10);
+ ld[0] = 0;
+ ld[1] = 1;
+ ld[2] = 65536;
+ ld[3] = 43046721;
+ ld[4] = 4294967296;
+ ld[5] = 152587890625;
+ ld[6] = 2821109907456;
+ ld[7] = 33232930569601;
+ ld[8] = 281474976710656;
+ ld[9] = 1853020188851841;
+# define MAYBE_LD_1(fn) \
+ ret_ld = fn(ld); \
+ print_array("Result of " # fn "(ld):", ret_ld);
+# define MAYBE_LD_2(fn) \
+ ldld = ld[0]; \
+ ret_ld = fn(ld, ld); \
+ print_array("Result of " # fn "(ld, ld):", ret_ld); \
+ ret_ld = fn(ldld, ld); \
+ print_array("Result of " # fn "(type, ld):", ret_ld); \
+ ret_ld = fn(ld, ldld); \
+ print_array("Result of " # fn "(ld, type):", ret_ld);
+#else
+# define MAYBE_LD_1(fn) /**/
+# define MAYBE_LD_2(fn) /**/
+#endif
+#define DO_1(fn) \
+ ret_d = fn(d); \
+ print_array("Result of " # fn "(d):", ret_d); \
+ ret_f = fn(f); \
+ print_array("Result of " # fn "(f):", ret_f); \
+ MAYBE_LD_1(fn)
+#define DO_2(fn) \
+ dd = d[0]; \
+ ret_d = fn(d, d); \
+ print_array("Result of " # fn "(d, d):", ret_d); \
+ ret_d = fn(dd, d); \
+ print_array("Result of " # fn "(type, d):", ret_d); \
+ ret_d = fn(d, dd); \
+ print_array("Result of " # fn "(d, type):", ret_d); \
+ ff = f[0]; \
+ ret_f = fn(f, f); \
+ print_array("Result of " # fn "(f, f):", ret_f); \
+ ret_f = fn(ff, f); \
+ print_array("Result of " # fn "(type, f):", ret_f); \
+ ret_f = fn(f, ff); \
+ print_array("Result of " # fn "(f, type):", ret_f); \
+ MAYBE_LD_2(fn)
+ DO_1(acos)
+ DO_1(asin)
+ DO_1(atan)
+ DO_2(atan2)
+ DO_1(cos)
+ DO_1(cosh)
+ DO_1(exp)
+ DO_1(log)
+ DO_1(log10)
+ DO_2(pow)
+ DO_1(sin)
+ DO_1(sinh)
+ DO_1(sqrt)
+ DO_1(tan)
+ DO_1(tanh)
+ std::cout << std::endl;
return 0;
}
More information about the uClibc-cvs
mailing list