Skip to content

Commit 50150bd

Browse files
committed
prevent sqrt to be computed on ints
1 parent 313354b commit 50150bd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/operators.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using namespace Eigen;
1818
Eigen::MatrixXd L(const Eigen::VectorXd& w) {
1919
int j;
2020
int k = w.size();
21-
const int n = .5 * (1 + sqrt(1 + 8 * k));
21+
const int n = .5 * (1 + sqrt(1. + 8. * k));
2222
Eigen::MatrixXd Lw = Eigen::MatrixXd::Zero(n, n);
2323

2424
for (int i = n-2; i > -1; --i) {
@@ -47,11 +47,11 @@ Eigen::MatrixXd L(const Eigen::VectorXd& w) {
4747
Eigen::MatrixXd A(const Eigen::VectorXd& w) {
4848
int j;
4949
int k = w.size();
50-
const int N = .5 * (1 + sqrt(1 + 8 * k));
51-
Eigen::MatrixXd Aw = Eigen::MatrixXd::Zero(N, N);
50+
const int n = .5 * (1 + sqrt(1. + 8. * k));
51+
Eigen::MatrixXd Aw = Eigen::MatrixXd::Zero(n, n);
5252

53-
for (int i = N-2; i > -1; --i) {
54-
j = N - i - 1;
53+
for (int i = n-2; i > -1; --i) {
54+
j = n - i - 1;
5555
Aw.row(i).tail(j) = w.head(k).tail(j);
5656
k -= j;
5757
}

0 commit comments

Comments
 (0)