Skip to content

Commit 366f7ab

Browse files
authored
Merge pull request #1355 from jmarrec/avoid_nan_computations
Avoid computations with NaN in sssky_diffuse_table::compute
2 parents efd6c0b + b60425d commit 366f7ab

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

lpsolve/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ if(MSVC)
6565
set(ADD_CFLAGS "${ADD_CFLAGS} /DRoleIsExternalInvEngine /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE")
6666
set(ADD_CFLAGS "${ADD_CFLAGS} /DFPUexception /DNOFORTIFY /D LP_MAXLINELEN=0")
6767
else()
68-
set(ADD_CFLAGS "${ADD_CFLAGS} -Wall -DWX_PRECOMP -DCHECK_SOLUTION -DYY_NEVER_INTERACTIVE -DPARSER_LP
69-
-DINVERSE_ACTIVE=INVERSE_LUSOL -DRoleIsExternalInvEngine")
68+
set(ADD_CFLAGS "${ADD_CFLAGS} -Wall -DWX_PRECOMP -DCHECK_SOLUTION -DYY_NEVER_INTERACTIVE -DPARSER_LP -DINVERSE_ACTIVE=INVERSE_LUSOL -DRoleIsExternalInvEngine")
7069
endif()
7170
set_additional_compile_options(lpsolve ${ADD_CFLAGS})
7271

shared/lib_pvshade.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ double sssky_diffuse_table::compute(double surface_tilt) {
302302
if (gcr == 0)
303303
throw std::runtime_error("sssky_diffuse_table::compute error: gcr required in initialization");
304304
// sky diffuse reduction
305-
const size_t n_steps = 250;
305+
const size_t n_steps = 250;
306306
double step = 1.0 / (double)n_steps;
307307
double skydiff = 0.0;
308308
double tand_stilt = tand(surface_tilt);
@@ -314,26 +314,26 @@ double sssky_diffuse_table::compute(double surface_tilt) {
314314
double Asky_shade[n_steps];
315315
for (int n = 0; n < n_steps; n++)
316316
{
317-
if (surface_tilt != 0)
317+
if (surface_tilt != 0) {
318318
arg[n] = (1 / tand_stilt) - (1 / (gcr * sind_stilt * (1 - n * step)));
319-
else
319+
gamma[n] = (-M_PI / 2) + atan(arg[n]);
320+
tan_tilt_gamma[n] = tan(surface_tilt * DTOR + gamma[n]);
321+
Asky_shade[n] = M_PI + M_PI / pow((1 + tan_tilt_gamma[n] * tan_tilt_gamma[n]), 0.5);
322+
if ((surface_tilt * DTOR + gamma[n]) > (M_PI / 2))
323+
{
324+
Asky_shade[n] = 2 * M_PI - Asky_shade[n];
325+
}
326+
skydiff += (Asky_shade[n] / Asky) * step;
327+
} else {
320328
arg[n] = std::numeric_limits<double>::quiet_NaN();
321-
gamma[n] = (-M_PI / 2) + atan(arg[n]);
322-
tan_tilt_gamma[n] = tan(surface_tilt * DTOR + gamma[n]);
323-
Asky_shade[n] = M_PI + M_PI / pow((1 + tan_tilt_gamma[n] * tan_tilt_gamma[n]), 0.5);
324-
if (std::isnan(Asky_shade[n]))
325-
{
329+
gamma[n] = std::numeric_limits<double>::quiet_NaN();
330+
tan_tilt_gamma[n] = std::numeric_limits<double>::quiet_NaN();
326331
Asky_shade[n] = Asky;
332+
skydiff += step;
327333
}
328-
else if ((surface_tilt * DTOR + gamma[n]) > (M_PI / 2))
329-
{
330-
Asky_shade[n] = 2 * M_PI - Asky_shade[n];
331-
}
332-
else {}
333-
skydiff += (Asky_shade[n] / Asky) * step;
334334
}
335335
int surface_tilt_key = int(surface_tilt * derates_table_digits_multiplier);
336-
derates_table[surface_tilt_key] = skydiff;
336+
derates_table[surface_tilt_key] = skydiff;
337337
return skydiff;
338338
}
339339

0 commit comments

Comments
 (0)