|
Boost : |
From: Paul A. Bristow (boost_at_[hidden])
Date: 2002-10-23 11:12:25
I had previously produced a naming scheme for constants, but this is now
in conflict with the naming scheme using by the recently introduced Interval
Library.
So I would appreciate views (I have a zero expectation of any consensus!!) on
the relative attractiveness of two schemes:
Previous Meth Constant Naming Convention
In general, a Standard Library C++ style is used, favouring longer and easier to
read names over ease of typing, and all lower case and underscore _ as
separator. Of course, names cannot start with a digit, so words, like two and
half, are used instead. C99 names are used where appropriate, but names are not
in all capitals as used in many C programs using the rationale that these names
are variable names and not macro or #define names.
Some examples, and a rationale for them, should make this clearer than an
attempt to write a formal specification. (Of course there are always problems
with more complex constants where brackets would be used).
pi // Prefer lower case only - use uppercase only for class_names and MACRO
constants.
ln_pi // _ as separator clearer than lnpi, even if longer and hard to type.
sqrt_2 // shorter than sqrt_two and clearer than sqrt2.
// sqrt is commonly used and much shorter than square_root_2.
cbrt_2 // ugly, but is C99 name.
ten // cant be decimal digits like 10 so use a word instead.
third // shorter than one_div_three.
one_div_sqrt_2 // one_div rather than reciprocal short but clear.
// _div rather than _on or _upon.
half_pi // rather than pi_div_2.
pi_sqr // pi_squared is rather long.
two_pow_three_halves // two_pow_three_div_two is ambiguous.
minus_ln_ln_2 // can't start with - sign so use word "minus".
Or should it be the Interval library convention that puts the constant name
first - an obvious plus point when making ordered lists - all the pi constants
will come together.
pi_half // should be halved?
pi_quarter // quarter_pi is nicer?
pi_twice // Not as clear as two_pi?
pi_thrice // Hmmm
pi_four_thirds // or four_thirds_pi
pi_four_times // four_pi is much better.
pi_times_four // four_pi is better?
pi_ln // Not so clear as ln_pi?
pi_log10 // base 10
pi_sqrt //
pi_sqr // as above scheme.
pi_cbrt // ugly but C99
pi_reciprocal // because can't have one_div_pi
two // fine.
two_sqrt // sqrt_2 or sqrt_two are much clearer.
five_cbrt // Hmmm.
one_minus // Nasty compared to minus_one or minus_1
half_minus //
And while I am seeking views on names, do the following seem sensible:
Explicit typed names
pi_f // float
pi_d // double
pi_l // long double or pi_l ??
// Potential ambiguity of long int and long double here!
// C standard ISO 9899:1999 (a.k.a. C99) choses _l for long double
pi_i // integer
pi_li // long integer // or pi_l conflists with C99 ??
Interval limit static const constant variable names - add _l and _u
pi // nearest to pi (usually == either upper and/or lower interval limit)
pi_l // pi interval lower limit
pi_u // pi interval upper limit
pi_f_l // pi float lower limit
pi_l_l // pi long double lower limit
pi_l_u // pi long double upper limit
Are there any other precedents or good examples - before I expose Math Cosntants
to another Formal Review. I think consistency in naming is surprisingly
important.
Thank you.
Paul
PS Has anyone devised or used a 32, 64 or 128 bit signed or unsigned fractional
type (in C++) - like a floating point type with all significand and without
exponent.
Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
Mobile mailto:pabristow_at_[hidden]
mailto:pbristow_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk