-
-
Notifications
You must be signed in to change notification settings - Fork 3k
std: add the "elusive eight" special functions to std.math
#24966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
EnronEvolved
wants to merge
33
commits into
ziglang:master
Choose a base branch
from
EnronEvolved:statmath-resurrection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
17ead83
Add core statistical math functions
tiehuis cde04da
math/prob: Rename files with more descriptive english names
tiehuis 8ba90c0
Rename bessel functions j* to besselj*
tiehuis 4c8386e
Rename lgam to lnGamma
tiehuis 5f8b67f
Rename ndtr to normalDist and ndtri to inverseNormalDist
tiehuis 07c8d62
Rename incbet to incompleteBeta and incbi to inverseIncompleteBeta
tiehuis 4b8a876
Rename incomplete gamma functions
tiehuis c9f1478
Update math/prob documentation
tiehuis 3f6de49
Return result for airy fn instead of taking pointers to modify
tiehuis c3f8b16
Update doc comment
tiehuis dcfcfac
A few TODOs, and added notes on constants
EnronEvolved 34c1b6a
Updated for loops in stdlib polevl.zig to new syntax, updated inverse…
EnronEvolved e8e10ac
Notes and minor style tweaks in math/prob/normal_dist.zig
EnronEvolved abc622d
nixed usingnamespace
EnronEvolved c4e56cb
fixed illegal bytes in comments, updated builtin names, and patched u…
EnronEvolved 8a6e773
fixed unused captures and more undefinitions from nizing usingnamespace
EnronEvolved 3fbe10a
fix moar
EnronEvolved d56f435
fix MOAR
EnronEvolved 5d4e63b
constgate fixes, and two usingnamespace undef fixes
EnronEvolved 490a3a7
constgate 2: const gater
EnronEvolved 93261a2
Initial fixes to build tests
EnronEvolved f28756c
Final changes to get build success and tests passing
EnronEvolved 2827068
Lifted constants defined in std/math/prob to std/math.zig
EnronEvolved 32e4fda
Constant lifting, phase 2
EnronEvolved 9b46279
Finished lifting constants
EnronEvolved c113149
Switched out most float-related constants for calls to comptime zig f…
EnronEvolved 4339df0
Clarified comments in prob/constants.zig, migrated constants with wel…
EnronEvolved 5fb81a3
Clarified airy function code, mostly with comments, but also by renam…
EnronEvolved d2275c4
migrate moar
EnronEvolved c2b125d
airy.zig: documented whatever the hell those are.
EnronEvolved aa7ca40
once-over with zig fmt
EnronEvolved 882516e
Corrected inverseNormalDist as suggested by @PauloCampana
EnronEvolved 3f7d6ec
nixed SPDX-License-Identifier in std/math/prob.zig
EnronEvolved File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2015-2021 Zig Contributors | ||
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. | ||
// The MIT license requires this copyright notice to be included in all copies | ||
// and substantial portions of the software. | ||
const std = @import("std"); | ||
const testing = std.testing; | ||
const math = std.math; | ||
|
||
pub const normalDist = @import("prob/normal_dist.zig").normalDist; | ||
pub const inverseNormalDist = @import("prob/normal_dist.zig").inverseNormalDist; | ||
pub const erfc = @import("prob/normal_dist.zig").erfc; | ||
pub const erf = @import("prob/normal_dist.zig").erf; | ||
|
||
pub const besselj0 = @import("prob/besselj0.zig").besselj0; | ||
pub const bessely0 = @import("prob/besselj0.zig").bessely0; | ||
pub const besselj1 = @import("prob/besselj1.zig").besselj1; | ||
pub const bessely1 = @import("prob/besselj1.zig").bessely1; | ||
pub const besselj = @import("prob/besseljn.zig").besselj; | ||
|
||
pub const airy = @import("prob/airy.zig").airy; | ||
|
||
pub const incompleteGamma = @import("prob/incomplete_gamma.zig").incompleteGamma; | ||
pub const complementedIncompleteGamma = @import("prob/incomplete_gamma.zig").complementedIncompleteGamma; | ||
pub const inverseComplementedIncompleteGamma = @import("prob/incomplete_gamma.zig").inverseComplementedIncompleteGamma; | ||
|
||
pub const gamma = @import("prob/gamma.zig").gamma; | ||
pub const lnGamma = @import("prob/gamma.zig").lnGamma; | ||
|
||
pub const incompleteBeta = @import("prob/incomplete_beta.zig").incompleteBeta; | ||
pub const inverseIncompleteBeta = @import("prob/incomplete_beta.zig").inverseIncompleteBeta; | ||
|
||
pub const polevl = @import("prob/polevl.zig").polevl; | ||
pub const p1evl = @import("prob/polevl.zig").p1evl; | ||
|
||
test "math.prob" { | ||
_ = @import("prob/expx2.zig"); | ||
_ = @import("prob/polevl.zig"); | ||
|
||
_ = @import("prob/airy.zig"); | ||
_ = @import("prob/gamma.zig"); | ||
_ = @import("prob/incomplete_gamma.zig"); | ||
_ = @import("prob/incomplete_beta.zig"); | ||
_ = @import("prob/besselj0.zig"); | ||
_ = @import("prob/besselj1.zig"); | ||
_ = @import("prob/besseljn.zig"); | ||
_ = @import("prob/normal_dist.zig"); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the multiple "Cephes lift; expand" means that the constants should be recalculated to have at least 128 bit floating point precision? (113 bits of mantissa) - If so, here ya go :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these constants (
pi
,e
,phi
,rad_per_deg
deg_per_rad
) are actually less precise than the ones already instd/math.zig
.There doesn't appear to be any documented rationale for the precision of floating point constants. Most of them are sufficient for quadruple precision, but some (namely the aforementioned) exceed quadruple precision but remain insufficient for octuple precision.
I guess this is another reason for why I was asking about best practices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK comptime_float is just an f128, so these all match the required precision. Of course, I'd be happy to calculate them to a higher precision.