summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorlawnjelly <lawnjelly@gmail.com>2023-05-09 13:49:26 +0100
committerRĂ©mi Verschelde <rverschelde@gmail.com>2023-05-12 12:31:23 +0200
commitefbb28d09a2a4aaa53875edd827e08137f9f19f4 (patch)
tree01516ffb51e02974f48ac1643f38de29396ec6fd /doc
parentb91b8fce43ab9cb9f8c96f8c640acc801774b6b5 (diff)
Make acos and asin safe
A common bug with using acos and asin is that input outside -1 to 1 range will result in Nan output. This can occur due to floating point error in the input. The standard solution is to provide safe_acos function with clamped input. For Godot it may make more sense to make the standard functions safe. (cherry picked from commit 50c5ed4876250f785be54b8f6124e7663afa38dc)
Diffstat (limited to 'doc')
-rw-r--r--doc/classes/@GlobalScope.xml4
1 files changed, 2 insertions, 2 deletions
diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml
index 73f1fe9ad6..8c84a55ba0 100644
--- a/doc/classes/@GlobalScope.xml
+++ b/doc/classes/@GlobalScope.xml
@@ -65,7 +65,7 @@
<return type="float" />
<param index="0" name="x" type="float" />
<description>
- Returns the arc cosine of [param x] in radians. Use to get the angle of cosine [param x]. [param x] must be between [code]-1.0[/code] and [code]1.0[/code] (inclusive), otherwise, [method acos] will return [constant @GDScript.NAN].
+ Returns the arc cosine of [param x] in radians. Use to get the angle of cosine [param x]. [param x] will be clamped between [code]-1.0[/code] and [code]1.0[/code] (inclusive), in order to prevent [method acos] from returning [constant @GDScript.NAN].
[codeblock]
# c is 0.523599 or 30 degrees if converted with rad_to_deg(c)
var c = acos(0.866025)
@@ -76,7 +76,7 @@
<return type="float" />
<param index="0" name="x" type="float" />
<description>
- Returns the arc sine of [param x] in radians. Use to get the angle of sine [param x]. [param x] must be between [code]-1.0[/code] and [code]1.0[/code] (inclusive), otherwise, [method asin] will return [constant @GDScript.NAN].
+ Returns the arc sine of [param x] in radians. Use to get the angle of sine [param x]. [param x] will be clamped between [code]-1.0[/code] and [code]1.0[/code] (inclusive), in order to prevent [method asin] from returning [constant @GDScript.NAN].
[codeblock]
# s is 0.523599 or 30 degrees if converted with rad_to_deg(s)
var s = asin(0.5)