-
-
Notifications
You must be signed in to change notification settings - Fork 769
[doc-core:math] Documentation for core:math
package. (partials)
#4961
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
base: master
Are you sure you want to change the base?
Conversation
…procedure groups
… procedure groups
/* | ||
Return square root of given input. | ||
|
||
**Only accept floats** |
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 would probably also document the behavior for when the input is an inf
, nan
, a negative zero and possibly subnormal.
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.
yeah, that is a good point! I added more examples for the special cases according to Float_Class
enum
core/math/math.odin
Outdated
x_float : = 4.0 ; sqrt_x_float := math.sqrt(x_float) // using default type of f16 | ||
x_f16 :f16 = 30.90 ; sqrt_x_f16 := math.sqrt(x_f16) | ||
x_f16le :f16le = 50.0 ; sqrt_x_f16le := math.sqrt(x_f16le) | ||
x_f16be :f16be = 100 ; sqrt_x_f16be := math.sqrt(x_f16be) | ||
x_f32 :f32 = 4.89 ; sqrt_x_f32 := math.sqrt(x_f32) | ||
x_f32le :f32le = 3.14 ; sqrt_x_f32le := math.sqrt(x_f32le) | ||
x_f32be :f32be = 2.0 ; sqrt_x_f32be := math.sqrt(x_f32be) | ||
x_f64 :f64 = 0.0578 ; sqrt_x_f64 := math.sqrt(x_f64) | ||
x_f64le :f64le = 1000.6 ; sqrt_x_f64le := math.sqrt(x_f64le) | ||
x_f64be :f64be = 89.98 ; sqrt_x_f64be := math.sqrt(x_f64be) |
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.
Use the standard style convention here too please.
x_float: f64 = 4.0; sqrt_x_float := math.sqrt(x_float) // using default type of f64
x_f16: f16 = 30.90; sqrt_x_f16 := math.sqrt(x_f16)
x_f16le: f16le = 50.0; sqrt_x_f16le := math.sqrt(x_f16le)
x_f16be: f16be = 100; sqrt_x_f16be := math.sqrt(x_f16be)
x_f32: f32 = 4.89; sqrt_x_f32 := math.sqrt(x_f32)
x_f32le: f32le = 3.14; sqrt_x_f32le := math.sqrt(x_f32le)
x_f32be: f32be = 2.0; sqrt_x_f32be := math.sqrt(x_f32be)
x_f64: f64 = 0.0; sqrt_x_f64 := math.sqrt(x_f64)
x_f64le: f64le = 1000.0; sqrt_x_f64le := math.sqrt(x_f64le)
x_f64be: f64be = 89.98; sqrt_x_f64be := math.sqrt(x_f64be)
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.
Thank you! fixed it and added more examples for special cases according to Float_Class
…e conventions according to comment odin-lang/Odin#4961 (comment) and odin-lang/Odin#4961 (comment)
… types. added doc for `RAD_PER_DEG` and `DEG_PER_RAD` constant
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.
Many of these issues repeat so not that I didn't put them on every place of occurrence.
@@ -34,8 +37,8 @@ MAX_F64_PRECISION :: 16 // Maximum number of meaningful digits after the decimal | |||
MAX_F32_PRECISION :: 8 // Maximum number of meaningful digits after the decimal point for 'f32' | |||
MAX_F16_PRECISION :: 4 // Maximum number of meaningful digits after the decimal point for 'f16' | |||
|
|||
RAD_PER_DEG :: TAU/360.0 | |||
DEG_PER_RAD :: 360.0/TAU | |||
RAD_PER_DEG :: TAU/360.0 // Being used to convert degrees to radians. (see `math.to_radians`) |
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.
For documentation, although sounds counterintuitive, you should duplicate it rather than making references to other points of documentation. For constants of the kind X_PER_Y
I suggest you show how to use these constants to perform the conversion.
**Only accept floats** | ||
|
||
Inputs: | ||
- x: input value of type floats |
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.
Although pkg.odin-lang
might do this conversion automatically, you should respect the LSP and wrap inputs and return value names in backticks, like this:
- `x`: Input value.
Also please form a proper sentence when describing inputs and returns of a procedure. Meaning, capitalizing the first letter and putting a period at the end.
You don't have to specify that x
in this function is a float, because you already specified this in the Note above. The point of this section is to establish a connection between the function parameters and its description.
y_f64be_nan: f64be = math.nan_f64be(); sqrt_y_f64be_nan := math.sqrt(y_f64be_nan) // NaN | ||
y_f16le_nan: f16le = math.nan_f16le(); sqrt_y_f16le_nan := math.sqrt(y_f16le_nan) // NaN | ||
|
||
Output: |
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.
Your example doesn't "print" anything, so there's no "output". This is going to be a problem with the documentation tester that runs all examples inside documentation and checks the output. I suggest you reformat these examples to print results. Might help to not focus on types as much as on values.
|
||
**Only accept floats** | ||
|
||
math.sin assumes input in radians. |
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.
math.sin assumes input in radians. | |
This procedure assumes the input angle in radians. |
@@ -60,7 +114,52 @@ sqrt :: proc{ | |||
@(require_results) sin_f32be :: proc "contextless" (θ: f32be) -> f32be { return #force_inline f32be(sin_f32(f32(θ))) } | |||
@(require_results) sin_f64le :: proc "contextless" (θ: f64le) -> f64le { return #force_inline f64le(sin_f64(f64(θ))) } | |||
@(require_results) sin_f64be :: proc "contextless" (θ: f64be) -> f64be { return #force_inline f64be(sin_f64(f64(θ))) } | |||
// Return the sine of θ in radians. | |||
/* | |||
Return sine of given input in radian. |
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.
The result is not in "radians", better move the clarification in the description.
Return sine of given input in radian. | |
Calculates the sine of a value. |
to_radians :: proc{ | ||
to_radians_f16, to_radians_f16le, to_radians_f16be, | ||
to_radians_f32, to_radians_f32le, to_radians_f32be, | ||
to_radians_f64, to_radians_f64le, to_radians_f64be, | ||
} | ||
/* | ||
Convert given input to degrees. |
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.
Convert given input to degrees. | |
Converts a given angle, in radians, to degrees. |
@@ -1790,7 +2071,91 @@ atan2 :: proc{ | |||
atan2_f16le, atan2_f16be, | |||
} | |||
|
|||
// Return the arc tangent of x, in radians. Defined on the domain of [-∞, ∞] with a range of [-π/2, π/2] | |||
/* | |||
Return inverse of tangent (arctan) of given input. |
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.
Return inverse of tangent (arctan) of given input. | |
Computes the inverse of tangent (arctan) of given input. |
- x: ouput value that with same type of the input in radians | ||
|
||
Example: | ||
x30_f32: f32 = 30.0; tan_x30_f32 := math.tan(x30_f32); atan_x30_f32 := math.atan(tan_x30_f32) // without converting to radians |
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.
This is going to look horrible in the text editor with wrapping on documentation snippets, and would require some scrolling on the website. Maybe you should wrap these manually
invers_asin_x60: f64le = math.to_degrees(asin_x60_f64le) | ||
invers_asin_x60_rad: f64le = math.to_degrees(asin_x60_f64le_rad) | ||
|
||
// special cases. (see Float_Class and math.classify) |
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.
Got indentation problems here. Should be tabs
and x is set to 1. See math.atan2 for detail. | ||
|
||
Beware of special cases i.e. `-0.0`, `+0.0`, `-Inf`, `+Inf`, and `Nan` (see examples). | ||
For special cases related math.atan2(x, 1) |
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.
Should change that to just listing special cases for atan
without referring to atan2
.
Documented: (all of this will be gradually updated)
math.Float_Class
enummath.sqrt
proc groupmath.sin
proc groupmath.cos
proc groupmath.tan
proc groupmath.to_radians
proc groupmath.to_degrees
proc groupDEG_PER_RAD
constantRAD_PER_DEG
constantmath.asin
proc groupmath.acos
proc groupmath.atan
proc groupMore detail underlying explanation/issue in #2358 (comment)