This backports the work in #7815 and the subsequent fixes in #8393
The following program now works as expected in this branch in both
release_debug and debug mode:
```gdscript
print(sqrt(-1))
print(sqrt(-1))
var simple1=asin(10.0)
var simple2=acos(10.0)
print(simple1)
print(simple2)
```
And successfully prints -nan 4 times
This fixes#9580 and fixes#8925