Comments (8)
This is covered by the root
function in the API, but the implementation needs to catch up:
Double.root(1000, 3)
This "should" produce 10, but there's currently a placeholder implementation that uses pow(x, 1/n)
. I'll re-purpose this bug to cover fixing that.
from swift-numerics.
Thanks for your answer! I was trying to understand to see if I could help.
Sent with GitHawk
from swift-numerics.
Related to #9
from swift-numerics.
Hey @stephentyrone, Do you think that the best solution is to implement it from scratch, or do you have something else in mind?
from swift-numerics.
Implementing from scratch is in some ways the simplest option, but also requires the most work (and incurs the most ongoing validation burden--I wrote the system pow
for Apple's platforms, so I know exactly how to implement root
, but I also definitely know very much how much work maintaining math library functions entails).
C2x should add rootn
to the standard C library; ideally we'll simply use that when it's available. But, it remains to be seen just how quickly it becomes available on various platforms that Swift targets.
It's possible to fix-up exact cases (on platforms with a sub-ulp accurate pow
) by computing pow(result, n)
and comparing to x
. This is really simple, but unnecessarily slow, and doesn't work if the host system pow
isn't good enough.
We could special-case n=2
and n=3
; that would cover 99% of exact use cases on Darwin (but I'm not sure about the quality of cbrt
on other platforms), but still leaves the bug in place for the rare 1% of cases.
I think I'll probably end up implementing root
directly, but there's other stuff that I'll attend to first, since the error here is tolerable most of the time.
from swift-numerics.
Ah. It's a deceptively tricky issue to handle well; if you're interested in a small quick fix, special casing 2
and 3
should be easy. The other steps are all pretty involved =)
from swift-numerics.
@stephentyrone, are there any cases where pow(x, 1/2)
returns an inexact result?
from swift-numerics.
@Roman-Kerimov Not on a system with a good-quality math library (because 1/2 is representable, if pow
has sub-ulp accuracy then pow(x, 1/2)
will get all exact cases right). The problem with pow(x, 1/3)
is that 1/3
is not representable in a binary floating-point type.
When a host-system pow
does not have sub-ulp accuracy, then pow(x, 1/2)
will probably be wrong for some cases as well.
from swift-numerics.
Related Issues (20)
- Feature request for "relaxed" floating-point semantics HOT 2
- Floating point exponent `pow` returns NaN for integer exponents HOT 2
- Possible improvement in 'pow' Elementary Function when operands are zero HOT 5
- Should complex multiplication use augmented arithmetic? HOT 1
- Warnings in `Double.testIntegerExponent()` HOT 1
- [BigInt] Using tests from “Violet - Python VM written in Swift” HOT 5
- Duplicate symbols on Windows
- "^=" xor function code was incorrect. HOT 1
- Improve String init() execution time and fix Violet bugs
- Change default branch from `Quaternions` to `main`
- `** ARCHIVE FAILED **` due to `_NumericsShims` missing HOT 4
- Crash in `DoubleWidth` HOT 4
- Variadic GCD and LCM
- Feature request: GCD for floating-point HOT 7
- Error in Swift Playgrounds HOT 1
- Issues with CMake support HOT 3
- [FR]: Support Apple Privacy Manifest HOT 1
- Extracting the real and imaginary part of a complex number HOT 4
- Always warning in Xcode with version 1.0.2
- BFloat16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-numerics.