[tor-bugs] #25368 [Core Tor/Tor]: Update the Tor Rust coding standards for new types

Tor Bug Tracker & Wiki blackhole at torproject.org
Wed Mar 14 03:05:51 UTC 2018


#25368: Update the Tor Rust coding standards for new types
----------------------------------------+----------------------------------
 Reporter:  teor                        |          Owner:  (none)
     Type:  defect                      |         Status:  assigned
 Priority:  Medium                      |      Milestone:  Tor:
                                        |  0.3.4.x-final
Component:  Core Tor/Tor                |        Version:
 Severity:  Normal                      |     Resolution:
 Keywords:  doc, rust, review-group-34  |  Actual Points:
Parent ID:  #23061                      |         Points:  0.5
 Reviewer:  isis                        |        Sponsor:
----------------------------------------+----------------------------------
Changes (by teor):

 * owner:  teor => (none)
 * status:  merge_ready => assigned


Comment:

 Replying to [comment:5 isis]:
 > This looks great!  A couple thoughts:
 >
 > 1) I only know enough about floating point arithmetic to stay away from
 it. That said, I was under the impression that
 [https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-
 numbers-2012-edition/ different compilers (and/or different compiler
 flags) can treat bitwise-identical floating points differently],

 We can write unit tests for issues like this, but I don't think they will
 affect us.

 > and I worry in general that—if we allow `f{16,32,64}`s to cross the FFI
 boundary, that the C compiler on one side will treat them differently to
 how the Rust compiler does. I'm not sure how much this matters for the
 applications where we're using floating points, which seem mostly
 localised to the system using them

 "Raw transmutation from u64.

 This is currently identical to transmute::<u64, f64>(v) on all platforms.
 It turns out this is incredibly portable, for two reasons:

 Floats and Ints have the same endianess on all supported platforms.
 IEEE-754 very precisely specifies the bit layout of floats.

 However there is one caveat…"

 https://doc.rust-lang.org/std/primitive.f64.html#method.from_bits

 The caveat doesn't apply, because we aren't transmitting binary floats
 over the network. We don't even want to transmit decimal floats over the
 network. Nor would we ever transmit NaNs over the network.

 > (i.e. we're not sending floats over the network and expecting others to
 interpret them exactly as we do, right?).

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/25368#comment:9>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list