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

Make subcrates #![no_std] #216

Closed
4 tasks
hauleth opened this issue Aug 9, 2016 · 13 comments
Closed
4 tasks

Make subcrates #![no_std] #216

hauleth opened this issue Aug 9, 2016 · 13 comments
Assignees
Milestone

Comments

@hauleth
Copy link
Member

hauleth commented Aug 9, 2016

  • num-traits
  • num-integer
  • num-complex
  • num-iter
@hauleth hauleth self-assigned this Aug 9, 2016
@hauleth hauleth added this to the v0.2.0 milestone Aug 9, 2016
@cuviper
Copy link
Member

cuviper commented Aug 18, 2016

I noticed in the 1.11 release notes that to_degrees and to_radians were just now stabilized in libcore. Things like this will constrain our rust version for going no_std. (But when we do make the breaking transition, we'll be choosing a new rust base anyway.)

jswrenn added a commit to jswrenn/num that referenced this issue Nov 1, 2016
jswrenn added a commit to jswrenn/num that referenced this issue Nov 1, 2016
jswrenn added a commit to jswrenn/num that referenced this issue Nov 1, 2016
@emberian
Copy link

Any timeline on when this will be done? Especially num-traits?

@Kixunil
Copy link

Kixunil commented Mar 25, 2017

I'm interested in this too.

to_radians and to_degrees can be implemented easily without Rust support. It's simply self * PI / 180.0 and self * 180.0 / PI (with appropriate conversion).

@vks
Copy link
Contributor

vks commented May 30, 2017

I started working on porting num-traits to no_std. However, I run into a very irritating problem:

error[E0308]: mismatched types
   --> src/sign.rs:116:38
    |
116 |                 <$t>::abs_sub(*self, *other)
    |                                      ^^^^^^ expected &f64, found f64
...
141 | signed_float_impl!(f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY);
    | -------------------------------------------------------------------- in this macro invocation
    |
    = note: expected type `&f64`
               found type `f64`
    = help: try with `&*other`

Removing the * does not work:

error[E0308]: mismatched types
   --> src/sign.rs:116:38
    |
116 |                 <$t>::abs_sub(*self, other)
    |                                      ^^^^^ expected f64, found &f64
...
141 | signed_float_impl!(f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY);
    | -------------------------------------------------------------------- in this macro invocation
    |
    = note: expected type `f64`
               found type `&f64`

So the compiler expects f64 and &f64 in the same place?

@vks
Copy link
Contributor

vks commented May 30, 2017

Even fixing that problem by reimplementing abs_sub it still does not work:

error: no method named `is_finite` found for type `f64` in the current scope
   --> src/cast.rs:231:19
    |
231 |             if !n.is_finite() || (-max_value as f64 <= n && n <= max_value as f64) {
    |                   ^^^^^^^^^
...
273 | impl_to_primitive_float!(f32);
    | ------------------------------ in this macro invocation
    |
    = help: items from traits can only be used if the trait is in scope; the following traits are implemented but not in scope, perhaps add a `use` for one of them:
    = help: candidate #1: `use float::Float;`
    = help: candidate #2: `use core::num::Float;`

core::num::Float is not stable and float::Float seems to cause an infinite recursion.

@Kixunil
Copy link

Kixunil commented May 30, 2017

Maybe .borrow() could help? (Just a guess, didn't see entire code)

@vks
Copy link
Contributor

vks commented May 30, 2017

I backported is_finite from core::num::Float. It is just a few lines and does not use unstable intrinsics. However, now I'm getting infinite recursions in float.rs because it seems like almost all math functions are not implemented in core. This means we would have to depend on another crate to implement them.

@vks
Copy link
Contributor

vks commented May 30, 2017

I think the best way forward is to split Float into the parts that require std and the parts that don't. This way it can be used by other crates for sorting floats (they don't need cos, sin, etc.).

@cuviper
Copy link
Member

cuviper commented May 30, 2017

Given that #[lang = "f32"] and #[lang = "f64"] are in libstd, I'm tempted to say that we should just chop all floating point from num #![no_std]. But if you can reasonably hang on to some core-only pieces, then let's see what remains...

@vks
Copy link
Contributor

vks commented May 30, 2017

But if you can reasonably hang on to some core-only pieces, then let's see what remains...

I think we should support everything in this file and the basic operations (Add, Sub, Mul, ...). That would be enough for e.g. sorting floats.

@cuviper
Copy link
Member

cuviper commented May 30, 2017

I think it's fine to exclude core's unstable Float methods. Those are basically all the methods that are lang items in std, so we don't need to support them in no_std. That still leaves the constants and basic ops.

@vks
Copy link
Contributor

vks commented May 30, 2017 via email

vks added a commit to vks/num that referenced this issue May 31, 2017
This makes it possible to build `traits` without `std`. For this a new
trait `BasicFloat` was introduced, implementing some basic functionality
that works with `core`. Most notably this is lacking functions like
`cos`, `sin`, etc.

`Float` is not available without `std`.

Refs rust-num#216.
vks added a commit to vks/num that referenced this issue May 31, 2017
This makes it possible to build `traits` without `std`. For this a new
trait `BasicFloat` was introduced, implementing some basic functionality
that works with `core`. Most notably this is lacking functions like
`cos`, `sin`, etc.

`Float` is not available without `std`.

Refs rust-num#216.
vks added a commit to vks/num that referenced this issue May 31, 2017
This makes it possible to build `traits` without `std`. For this a new
trait `BasicFloat` was introduced, implementing some basic functionality
that works with `core`. Most notably this is lacking functions like
`cos`, `sin`, etc.

`Float` is not available without `std`.

Refs rust-num#216.
homu added a commit that referenced this issue Jun 9, 2017
traits: Introduce std feature

This makes it possible to build `traits` without `std`. For this a new
trait `BasicFloat` was introduced, implementing some basic functionality
that works with `core`. Most notably this is lacking functions like
`cos`, `sin`, etc.

`Float` is not available without `std`.

Refs #216.
@cuviper cuviper mentioned this issue Jun 9, 2017
@cuviper
Copy link
Member

cuviper commented Dec 19, 2017

@cuviper cuviper closed this as completed Dec 19, 2017
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

5 participants