Comments (11)
I think those implicits will probably need to be opt-in, since many users may not want this behavior by default. But it's a good point. We can certainly give Number implicits to go from all the other number types to Number.
from spire.
Hi Erik and others. Hope you don't mind me throwing my 2 cents in. I'm attempting to build a parametric geometry modeler using spire, because one nice feature would the ability to use doubles, complex numbers, or even hyper dual numbers. Therefore, I am writing all my methods using the spire version of Numeric. I have noticed I have to always use the fromDouble() method to work with literal doubles, however. Are there some implicits I'm failing to import? Would be nice to not have to write:
val y = x * fromDouble(2.0) // wish it could be x * 2.0 and get y:Numeric[Double]
fyi, x is a Numeric[Double]
just my thoughts and yes I am new to Scala and spire...but learning fast. thanks for your contributions. hope I can help in some way someday soon.
from spire.
Hm. I guess the best way to accomplish all of this would be to have some optional packages that can be imported to achieve this. These behaviors are probably not great to have on all-the-time although I totally see why they would be useful.
I'm still working on some of the other changes to Number. I'll try to push those tonight so you all can give some feedback.
from spire.
This should be working in the 2.10.0 branch. (For Number). No extra imports should be required besides spire.math._.
dlrodriguez, can you open a new ticket for your issue? I will look into it but I'm going to close this one since it is working for me now.
from spire.
It seems to work only in one direction:
scala> Number(1) + SafeLong(7)
res5: spire.math.Number = IntNumber(8)
scala> SafeLong(7) + Number(1)
:48: error: could not find implicit value for evidence parameter of type spire.algebra.AdditiveMonoid[scala.math.ScalaNumericConversions with scala.math.Ordered[_ >: spire.math.SafeLong with spire.math.Number <: scala.math.ScalaNumericConversions with scala.math.Ordered[_ >: spire.math.SafeLong with spire.math.Number <: scala.math.ScalaNumericConversions]]]
SafeLong(7) + Number(1)
from spire.
Hm, I thought I tested that. Time to work on it some more...
from spire.
This should be fixed again.
from spire.
But it gets the wrong type, when the safelong is left:
scala> Number(1) + SafeLong(7)
res12: spire.math.Number = IntNumber(8)
scala> SafeLong(7) + Number(1)
res9: spire.math.Number = FloatNumber(8.0)
On 01/06/2013 01:47 AM, Erik Osheim wrote:
This should be fixed again.
—
Reply to this email directly or view it on GitHub
#45 (comment).
from spire.
Yeah, that is going to be a little more difficult to fix. All I can say is that implicit conversions are annoying and it's really easy to hit ambiguities. Right now we're just converting to Double in that position so that all conversions pass through the same implicit and we avoid ambiguity.
I don't love it either, but I can't promise it will be fixed soon. Given that Scala has special built-in support for numeric coercisions (which only works for the built-in types) I can't promise that all of Spire's types are going to magically coerce quite as well as we'd like.
from spire.
Actually nevermind there probably is an easier way to fix this.
from spire.
This should be improved now. Thanks for your feedback!
from spire.
Related Issues (20)
- Integrate with new algebra typeclasses HOT 1
- v0.18.0 migration guide
- set version scheme
- setup header plugin
- `NoImplicit` probably won't work on Scala 3? HOT 2
- Check that site/docs build in CI, run for PRs HOT 3
- Outdated Issues HOT 1
- `NaturalScalaCheckSuite.x % y` failed on Scala.js
- `RealScalaCheckSuite.x.pow(k).nroot(k) = x` failed HOT 3
- Fast-path for rounding `Real` HOT 1
- Change `fastFor` back to `cfor`
- Markdown sections with `[ ]` don't render in site
- Jar content files has future date HOT 4
- Use of bug in `cfor` macro HOT 4
- Simple example works on scastie but does not compile when using sbt HOT 5
- cleaner typeclass instances for `Fractional` HOT 1
- InnerProductSpace working example
- RFE: inline methods for spire algebra typeclass instances HOT 3
- `Complex` `atan2` and `tanh` are wrong
- Gaussian sampler crashes randomly with ArrayIndexOutOfBoundsException
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 spire.