Skip to content
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

Problems with ** #13

Open
roytu opened this issue Jul 21, 2014 · 2 comments
Open

Problems with ** #13

roytu opened this issue Jul 21, 2014 · 2 comments

Comments

@roytu
Copy link

roytu commented Jul 21, 2014

The ** operator triggers an exception when the base is 0 or negative. Tested with Prec10 and Prec50 for epsilon values.

Prelude> :module + Data.Number.Fixed
Prelude Data.Number.Fixed> (0 ** 2) :: Fixed Prec10
Loading package numbers-3000.2.0.1 ... linking ... done.
*** Exception: Fraction.log
Prelude Data.Number.Fixed> (0 ** (-2)) :: Fixed Prec10
*** Exception: Fraction.log
Prelude Data.Number.Fixed> ((-2) ** 2) :: Fixed Prec10
*** Exception: Fraction.log
Prelude Data.Number.Fixed> 

Probably makes sense that negative values crash, but 0 shouldn't.

@crockeea
Copy link

This really is a deficiency of Haskell's Floating class. It gives a default implementation for (**) which is

x ** y = exp ((log x) * y)

and of course log 0 is undefined. For a similar reason, an error also occurs for sqrt (0 :: Fixed Prec10).

@EarthCitizen
Copy link

In some cases the behavior is not the same as built-in types:

> (-1) ** (-5) :: Double
-1.0

> (-1) ** (-5) :: BigFloat Prec50
*** Exception: Fraction.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants