Blitz logo

Blitz Bugs :

From: Julian Cummings (cummings_at_[hidden])
Date: 2004-02-10 15:00:10


Hello,

The sqr() and sqrt() functions are listed in the blitz documentation as
single-argument math functions that may be applied elementwise to blitz
Arrays. They are not meant to be applied to scalar types like int or
double. That is why the calls with scalar arguments fail. Of course,
there is a std::sqrt() function available for floating-point scalar
types. It doesn't work for an integral type because of ambiguity.

By the way, the sqr() function is implemented in terms of a helper
function blitz_sqr() that is generally templated to multiply any type T
by itself. So you could use blitz_sqr() on scalar types. I don't
recommend that, since this is an implementation detail that might change
in the future. Just write x*x or create your own macro for this if
necessary.

Regards, Julian C.

J H Al-Sadah wrote:

> Hi,
>
> I thought sqr() and sqrt() works for arrays and native types of int
> and doubles. Apparently, this is not the case. They works for array
> objects. Bellow, is a test code with notes.
>
>
>
> Regards,
>
>
>
> J. H. Al-Sadah
>
>
>
>
>
>
>
> //--------------------
>
> #include <blitz/array.h>
>
> #include <iostream>
>
> #include <fstream>
>
>
>
>
>
> using namespace std;
>
> using namespace blitz;
>
>
>
> int main(int argc,char **argv)
>
> {
>
> Array<double,1> aa(1), bb(1);
>
> aa = 9;
>
> bb = sqr(aa); cout << endl << bb << endl; // works
>
> bb = sqrt(aa); cout << endl << bb << endl; // works
>
>
>
> cout << endl << sqrt(5.0) << endl; // ok
>
> cout << endl << sqrt(5) << endl; // warnning + not working
>
> cout << endl << sqr(5.) << endl; // not working
>
> cout << endl << sqr(5) << endl; // not working
>
> return 0;
>
> }
>
>
>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Blitz-bugs mailing list
>Blitz-bugs_at_[hidden]
>http://www.oonumerics.org/mailman/listinfo.cgi/blitz-bugs
>
>

-- 
Dr. Julian C. Cummings                       E-mail: cummings_at_[hidden]
California Institute of Technology           Phone:  626-395-2543
1200 E. California Blvd., Mail Code 158-79   Fax:    626-584-5917
Pasadena, CA 91125