comparison libinterp/corefcn/sparse-xpow.cc @ 28144:c31c9eaa1f28 stable

sparse-xpow.cc: use xisint instead of static_cast<int> to check int values
author John W. Eaton <jwe@octave.org>
date Thu, 27 Feb 2020 13:45:53 -0500
parents bd51beb6205e
children 0a5b15007766
comparison
equal deleted inserted replaced
28143:4f1d1b1d4afc 28144:c31c9eaa1f28
65 octave_idx_type nc = a.cols (); 65 octave_idx_type nc = a.cols ();
66 66
67 if (nr == 0 || nc == 0 || nr != nc) 67 if (nr == 0 || nc == 0 || nr != nc)
68 error ("for A^b, A must be a square matrix. Use .^ for elementwise power."); 68 error ("for A^b, A must be a square matrix. Use .^ for elementwise power.");
69 69
70 if (static_cast<int> (b) != b) 70 if (! xisint (b))
71 error ("use full(a) ^ full(b)"); 71 error ("use full(a) ^ full(b)");
72 72
73 int btmp = static_cast<int> (b); 73 int btmp = static_cast<int> (b);
74 if (btmp == 0) 74 if (btmp == 0)
75 { 75 {
133 octave_idx_type nc = a.cols (); 133 octave_idx_type nc = a.cols ();
134 134
135 if (nr == 0 || nc == 0 || nr != nc) 135 if (nr == 0 || nc == 0 || nr != nc)
136 error ("for A^b, A must be a square matrix. Use .^ for elementwise power."); 136 error ("for A^b, A must be a square matrix. Use .^ for elementwise power.");
137 137
138 if (static_cast<int> (b) != b) 138 if (! xisint (b))
139 error ("use full(a) ^ full(b)"); 139 error ("use full(a) ^ full(b)");
140 140
141 int btmp = static_cast<int> (b); 141 int btmp = static_cast<int> (b);
142 if (btmp == 0) 142 if (btmp == 0)
143 { 143 {
327 if (b <= 0.0) 327 if (b <= 0.0)
328 { 328 {
329 octave_idx_type nr = a.rows (); 329 octave_idx_type nr = a.rows ();
330 octave_idx_type nc = a.cols (); 330 octave_idx_type nc = a.cols ();
331 331
332 if (static_cast<int> (b) != b && a.any_element_is_negative ()) 332 if (! xisint (b) && a.any_element_is_negative ())
333 { 333 {
334 ComplexMatrix result (nr, nc, Complex (std::pow (0.0, b))); 334 ComplexMatrix result (nr, nc, Complex (std::pow (0.0, b)));
335 335
336 // FIXME: avoid apparent GNU libm bug by 336 // FIXME: avoid apparent GNU libm bug by
337 // converting A and B to complex instead of just A. 337 // converting A and B to complex instead of just A.
361 } 361 }
362 362
363 retval = octave_value (result); 363 retval = octave_value (result);
364 } 364 }
365 } 365 }
366 else if (static_cast<int> (b) != b && a.any_element_is_negative ()) 366 else if (! xisint (b) && a.any_element_is_negative ())
367 { 367 {
368 SparseComplexMatrix result (a); 368 SparseComplexMatrix result (a);
369 369
370 for (octave_idx_type i = 0; i < nz; i++) 370 for (octave_idx_type i = 0; i < nz; i++)
371 { 371 {
425 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++) 425 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
426 { 426 {
427 if (a.data(i) < 0.0) 427 if (a.data(i) < 0.0)
428 { 428 {
429 double btmp = b (a.ridx (i), j); 429 double btmp = b (a.ridx (i), j);
430 if (static_cast<int> (btmp) != btmp) 430 if (! xisint (btmp))
431 { 431 {
432 convert_to_complex = 1; 432 convert_to_complex = 1;
433 goto done; 433 goto done;
434 } 434 }
435 } 435 }