News for hackers. Stuff that matters.
Re:Rust 0.12.0 released by acqq on Thursday October 09, 2014 @03:02PM (#8434424)
> for floats there's a default that makes sense

Really? In C I use both doubles and floats all the time.

> i32 can't index an array

Why? Is it because Rust would use less than 32 bits for indexes on some platforms? And how should then the indexes for arrays be written?

You have really a hard job, when such basic things change?

Re:Rust 0.12.0 released by steveklabnik on Thursday October 09, 2014 @03:12PM (#8434466)
Unless you need the extra precision, using a float makes more sense than a double.

But with integers, it's different. It's not so much that an i32 _can't_ index an array, but that it _might not be able to_. On a 64 bit machine, you could have a very large array that's bigger than an i32 in size.

Re:Rust 0.12.0 released by acqq on Thursday October 09, 2014 @03:17PM (#8434490)
> Unless you need the extra precision, using a float makes more sense than a double.

No. Floats are OK for big storage, but for a lot of uses you want to make all the intermediate calculations in doubles and only when storing the results to convert to floats again. See

https://news.ycombinator.com/item?id=8434128

(at the moment top of the front page) where people have problem with Intel using 66 bits mantissa internally for the input of 53 bits (double!). You don't want to have partial results as floats unless you're doing graphics and simple calculations where you need much less bits. You'd would never like to calculate a bridge construction with floats, even if the needed parts would at the end be written with only 4 digits.

Re:Rust 0.12.0 released by steveklabnik on Thursday October 09, 2014 @03:26PM (#8434532)
That's what I intended as part of 'if you need the precision.' You're absolutely right that even if the beginning and end are floats, you may want to do the intermediate calculations as a double.
Re:Rust 0.12.0 released by acqq on Thursday October 09, 2014 @03:30PM (#8434555)
Therefore it's often important to have fp constants with as much bits as possible. But there are exceptions again: unless you use them to initialize float arrays etc.

Regarding indexes for arrays, there are typical uses that should be recognized: if I write a[ 1 ] I'd like to be able to address the element 1. If I write a[ 0xffffffffffff ] it's also clear it's more than 32 bits.

Re:Rust 0.12.0 released by steveklabnik on Thursday October 09, 2014 @03:40PM (#8434612)
Right. There's tons of reasonable choices here. Which is why Rust currently has no defaults, and is why you need to write 5i today.

This whole topic is very much still under discussion. While many want defaults, what they default to is still a question. And there's a sizable group that doesn't want any default at all.

Re:Rust 0.12.0 released by nophilosoraptor on Thursday October 09, 2014 @11:53PM (#8436183)
Floats are like 16-bit shorts. Useless.

There is little performance advantage to using a 32-bit float. Their precision is low enough that you can't do anything useful without risking the correctness of your program.

They are, like shorts, an artefact of the past. Unlike shorts, their limitations are not within the intuition of the average programmer, which leads to widespread abuse and bugs.

Kill them before it's too late.

Re:Rust 0.12.0 released by dbaupp on Friday October 10, 2014 @02:13AM (#8436478)
Floats (and shorts) have a significant performance advantage, when they're appropriate. For example, you can fit 2x as many floats into cache compare to a double and good cache behaviour is really important these days, it's one of the reasons languages like C/C++/Rust with good control over memory layout can be very fast. Also, you can operate on 2x as many floats with vectorised instructions; again, SIMD is important these days, especially for things like games (where the precision of a float is fine).
Re:Rust 0.12.0 released by yaantc on Friday October 10, 2014 @04:32AM (#8436775)
This is too brutal, you have to consider the application domain. For physics simulations I would agree with you. For signal processing or graphics applications float is usually perfectly fine (and even overkill for many DSP applications).

People mentioned the cache efficiency gain with floats, and that is already relevant to rust. If in the future maybe rust could be used for GPGPU, then the difference between float and double often becomes even more dramatic. You definitely want to keep float support for this.

Re:Rust 0.12.0 released by kibwen on Friday October 10, 2014 @09:52AM (#8437626)
Packets for networked multiplayer games are another place where half-precision floats are acceptable: http://www.gamasutra.com/blogs/MarkMennell/20140929/226628/M...

(Though it must be said that Rust doesn't actually have a 16-bit float type at all.)

Re:Rust 0.12.0 released by acqq on Friday October 10, 2014 @02:07AM (#8436457)
You are wrong. Ever played 60 fps games on smaller devices? They would not be possible without floats.