Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/ellipk/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,18 @@ function ellipk( m ) {
var x;

x = m;
td = 1.0 - m;
if ( m < 0.0 ) {
x = m / ( m - 1.0 );

// Form `1-x` as `1/(1-m)` rather than by subtracting `x` from one, which cancels as `m` grows more negative and gives `x = 1` once `m < -2^53`:
td = 1.0 / ( 1.0 - m );
FLG = true;
}
if ( x === 0.0 ) {
return HALF_PI;
}
if ( x === 1.0 ) {
if ( td === 0.0 && !FLG ) {
return PINF;
}
if ( x > 1.0 ) {
Expand All @@ -171,7 +175,6 @@ function ellipk( m ) {
} else if ( x < 0.9 ) {
t = poly10( x - 0.875 );
} else {
td = 1.0 - x;
qd = poly11( td );
kdm = poly12( td - 0.05 );
t = -ln( qd ) * ( kdm * ONE_DIV_PI );
Expand Down
7 changes: 5 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/ellipk/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,18 @@ double stdlib_base_ellipk( const double m ) {

FLG = 0;
x = m;
td = 1.0 - m;
if ( m < 0.0 ) {
x = m / ( m - 1.0 );

// Form `1-x` as `1/(1-m)` rather than by subtracting `x` from one, which cancels as `m` grows more negative and gives `x = 1` once `m < -2^53`:
td = 1.0 / ( 1.0 - m );
FLG += 1;
}
if ( x == 0.0 ) {
return STDLIB_CONSTANT_FLOAT64_HALF_PI;
}
if ( x == 1.0 ) {
if ( td == 0.0 && FLG == 0 ) {
return STDLIB_CONSTANT_FLOAT64_PINF;
}
if ( x > 1.0 ) {
Expand All @@ -382,7 +386,6 @@ double stdlib_base_ellipk( const double m ) {
} else if ( x < 0.9 ) {
t = poly_p10( x - 0.875 );
} else {
td = 1.0 - x;
qd = poly_p11( td );
kdm = poly_p12( td - 0.05 );
t = -stdlib_base_ln( qd ) * ( kdm * ONE_DIV_PI );
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ int main( void ) {
rand_array_f64( x, len, -1.0, 0.0);
generate( x, len, "medium_negative.json" );

rand_array_f64( x, len, -1.0e10, -1.0);
generate( x, len, "large_negative.json" );

// Free allocated memory:
free( x );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
julia 1.5
JSON 0.21

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env julia
#
# @license Apache-2.0
#
# Copyright (c) 2026 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import JSON

"""
ellipk( m )

Evaluate the complete elliptic integral of the first kind in extended precision.

# Arguments

* `m`: parameter

# Examples

``` julia
julia> y = ellipk( BigFloat( -1.0 ) );
```
"""
function ellipk( m )
# Use `K(m) = π / ( 2 * agm( 1, sqrt(1-m) ) )`, which holds for all `m < 1` without transforming a negative `m` into a parameter close to one:
a = BigFloat( 1 );
b = sqrt( 1 - m );
while abs( a - b ) > eps( a ) * 4
a, b = ( a + b ) / 2, sqrt( a * b );
end
return BigFloat( pi ) / ( a + b );
end

"""
gen( x, name )

Generate fixture data and write to file.

# Arguments

* `x`: input values
* `name::AbstractString`: output filename

# Examples

``` julia
julia> x = -rand( 1000 ) .* 1.0e10;
julia> gen( x, "data.json" );
```
"""
function gen( x, name )
y = setprecision( BigFloat, 2048 ) do
Float64.( ellipk.( BigFloat.( x ) ) );
end

# Store data to be written to file as a collection:
data = Dict([
("x", x),
("expected", y)
]);

# Based on the script directory, create an output filepath:
filepath = joinpath( dir, name );

# Write the data to the output filepath as JSON:
outfile = open( filepath, "w" );
write( outfile, JSON.json(data) );
write( outfile, "\n" );
close( outfile );
end

# Get the filename:
file = @__FILE__;

# Extract the directory in which this file resides:
dir = dirname( file );

# Large negative values:
x = -( rand( 4000 ) .* ( 1.0e10 - 1.0 ) .+ 1.0 );
gen( x, "large_negative.json" );

# Huge negative values (below `-2^53`, `m/(m-1)` rounds to one):
x = -exp10.( range( 10.0, stop = 300.0, length = 1000 ) );
gen( x, "huge_negative.json" );
21 changes: 19 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/ellipk/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
var mediumPositive = require( './fixtures/cpp/medium_positive.json' );
var closeToUnity = require( './fixtures/cpp/close_to_unity.json' );
var mediumNegative = require( './fixtures/cpp/medium_negative.json' );
var largeNegative = require( './fixtures/cpp/large_negative.json' );
var largeNegative = require( './fixtures/julia/large_negative.json' );
var hugeNegative = require( './fixtures/julia/huge_negative.json' );


// TESTS //
Expand Down Expand Up @@ -72,7 +73,7 @@

for ( i = 0; i < x.length; i++ ) {
y = ellipk( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 12065 ), true, 'returns expected value' ); // FIXME: investigate the reason for this large discrepancy

Check warning on line 76 in lib/node_modules/@stdlib/math/base/special/ellipk/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: investigate the reason for this...'
}
t.end();
});
Expand Down Expand Up @@ -104,7 +105,23 @@

for ( i = 0; i < x.length; i++ ) {
y = ellipk( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 204773163 ), true, 'returns expected value' ); // FIXME: investigate the reason for this large discrepancy
t.strictEqual( isAlmostSameValue( y, expected[ i ], 5 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the complete elliptic integral of the first kind (huge negative values)', function test( t ) {
var expected;
var x;
var y;
var i;

expected = hugeNegative.expected;
x = hugeNegative.x;

for ( i = 0; i < x.length; i++ ) {
y = ellipk( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 4 ), true, 'returns expected value' );
}
t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
var mediumPositive = require( './fixtures/cpp/medium_positive.json' );
var closeToUnity = require( './fixtures/cpp/close_to_unity.json' );
var mediumNegative = require( './fixtures/cpp/medium_negative.json' );
var largeNegative = require( './fixtures/cpp/large_negative.json' );
var largeNegative = require( './fixtures/julia/large_negative.json' );
var hugeNegative = require( './fixtures/julia/huge_negative.json' );


// VARIABLES //
Expand Down Expand Up @@ -81,7 +82,7 @@

for ( i = 0; i < x.length; i++ ) {
y = ellipk( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 12065 ), true, 'returns expected value' ); // FIXME: investigate the reason for this large discrepancy

Check warning on line 85 in lib/node_modules/@stdlib/math/base/special/ellipk/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: investigate the reason for this...'
}
t.end();
});
Expand Down Expand Up @@ -113,7 +114,23 @@

for ( i = 0; i < x.length; i++ ) {
y = ellipk( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 204773163 ), true, 'returns expected value' ); // FIXME: investigate the reason for this large discrepancy
t.strictEqual( isAlmostSameValue( y, expected[ i ], 5 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the complete elliptic integral of the first kind (huge negative values)', opts, function test( t ) {
var expected;
var x;
var y;
var i;

expected = hugeNegative.expected;
x = hugeNegative.x;

for ( i = 0; i < x.length; i++ ) {
y = ellipk( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 4 ), true, 'returns expected value' );
}
t.end();
});
Expand Down
Loading