[tor-bugs] #23368 [Core Tor/Tor]: Add design and coding guidelines for using floating point

Tor Bug Tracker & Wiki blackhole at torproject.org
Fri Sep 8 00:40:07 UTC 2017

#23368: Add design and coding guidelines for using floating point
 Reporter:  teor                              |          Owner:  catalyst
     Type:  enhancement                       |         Status:
                                              |  needs_revision
 Priority:  Medium                            |      Milestone:  Tor:
                                              |  0.3.2.x-final
Component:  Core Tor/Tor                      |        Version:
 Severity:  Normal                            |     Resolution:
 Keywords:  doc, tor-safety, review-group-23  |  Actual Points:
Parent ID:                                    |         Points:  0.5
 Reviewer:                                    |        Sponsor:
Changes (by teor):

 * status:  needs_review => needs_revision


 Replying to [comment:9 catalyst]:
 > Proposed patch in https://oniongit.eu/catalyst/tor/merge_requests/1

 Looks great!

 T1. It might help to be more specific here:
    - If you must send floating point numbers on the wire, serialize
      them in a platform-independent way. Tor avoids exchanging
      floating-point values. But when it does, it uses ASCII numerals,
      with a decimal point ("."). This is the "C" Locale Format.

 For reference, I could only find one floating-point value in all the
 directory documents.
 In extra-info documents, Tor uses the following C code:
 printf("epsilon=%.2f", EPSILON_CONSTANT)

 Which produces:

 T2. I'd also like to add some more notes like this:
    - Changing the order of operations changes the results of many
      floating-point calculations. Be careful when you simplify
      calculations! If the order is significant, document it using
      a code comment.
    - Comparing most floating point values for equality is unreliable.
      Avoid using `==`, instead, use `>=` or `<=`.
    - Testing floating-point outputs in unit tests is hard. Tests
      that work on your machine can fail in other environments.

 Once you've made these changes, feel free to flip this to "ready to

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

More information about the tor-bugs mailing list