Skip to content

Commit

Permalink
refactor: precompute constant
Browse files Browse the repository at this point in the history
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: passed
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: passed
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: passed
  - task: run_c_benchmarks
    status: passed
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: passed
---
  • Loading branch information
Planeshifter committed Jan 20, 2025
1 parent 441ea68 commit 5a6efed
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
// MODULES //

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var SQRT3 = require( '@stdlib/constants/float64/sqrt-three' );
var PI = require( '@stdlib/constants/float64/pi' );


// VARIABLES //

var PI_OVER_SQRT_THREE = 1.8137993642342178; // π divided by the square root of 3


// MAIN //
Expand Down Expand Up @@ -62,7 +65,7 @@ function stdev( mu, s ) {
) {
return NaN;
}
return s * PI / SQRT3;
return s * PI_OVER_SQRT_THREE;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "stdlib/constants/float64/pi.h"
#include "stdlib/constants/float64/sqrt_three.h"

static const double PI_OVER_SQRT_THREE = 1.8137993642342178; // π divided by the square root of 3

/**
* Returns the standard deviation for a logistic distribution with location `mu` and scale `s`.
*
Expand All @@ -40,5 +42,5 @@ double stdlib_base_dists_logistic_stdev( const double mu, const double s ) {
) {
return 0.0/0.0; // NaN
}
return s * STDLIB_CONSTANT_FLOAT64_PI / STDLIB_CONSTANT_FLOAT64_SQRT3;
return s * PI_OVER_SQRT_THREE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ tape( 'the function returns the standard deviation of a logistic distribution',
t.equal( y, expected[i], 'mu:'+mu[i]+', s: '+s[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 2.0 * EPS * abs( expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. mu: '+mu[i]+'. s: '+s[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ tape( 'the function returns the standard deviation of a logistic distribution',
t.equal( y, expected[i], 'mu:'+mu[i]+', s: '+s[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 2.0 * EPS * abs( expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. mu: '+mu[i]+'. s: '+s[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
}
Expand Down

0 comments on commit 5a6efed

Please sign in to comment.