Code Monkey home page Code Monkey logo

to-precision's People

Contributors

bebesparkelsparkel avatar bengt avatar epmoyer avatar randlet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

to-precision's Issues

Overbars

William,

I'm not going to drag over-bars into the scope of the already broad PR we're working on, but it turns out that there is a "COMBINING_OVERLINE" Unicode character (\u0305) that places an overline over the character it follows. One would have to deal with Python2 vs. 3 Unicode issues, and it wouldn't be useful to people unless the output device their data was headed for supported it (so it would have to be a unique mode option), but at least it is possible.

>>> print("130\u03050")
130ฬ…0
>>>

Food for thought :)

Add this to PyPi.

Add this to PyPi. As far as I can tell There is nothing like this that exists on there. It will make it very easy for users to pull your module.

Here is a simple guide.

Ability to handle NaNs

This looks very useful. However, is it true that it cannot handle NaNs?

---> 40 return converter(value, precision, filler)
41
42

/Volumes/Apps_and_Docs/JRR_Utils/anaconda/lib/python2.7/site-packages/to_precision.pyc in sci_notation(value, precision, filler)
82 [email protected]
83 '''
---> 84 is_neg, sig_digits, dot_power, ten_power = _sci_notation(value, precision)
85
86 return ('-' if is_neg else '') + _place_dot(sig_digits, dot_power) + filler + str(ten_power)

/Volumes/Apps_and_Docs/JRR_Utils/anaconda/lib/python2.7/site-packages/to_precision.pyc in _sci_notation(value, precision)
123 [email protected]
124 '''
--> 125 sig_digits, power, is_neg = _number_profile(value, precision)
126
127 dot_power = -(precision - 1)

/Volumes/Apps_and_Docs/JRR_Utils/anaconda/lib/python2.7/site-packages/to_precision.pyc in _number_profile(value, precision)
191
192 power = -1 * math.floor(math.log10(value)) + precision - 1
--> 193 sig_digits = str(int(round(abs(value) * 10.0**power)))
194
195 return sig_digits, int(-power), is_neg

ValueError: cannot convert float NaN to integer

Inconsistent sig figs with values <1

This is a really nice library. I think I've found a minor bug:

>>> std_notation(0.989999, 3)
'0.990' # good
>>> std_notation(0.999999, 3)
'1.000' # extra sig fig
>>> std_notation(1.0, 3)
'1.00' # good
>>> std_notation(1.00000, 3)
'1.00' # good
>>> std_notation(0.099999, 3)
'0.1000' # extra sig fig
>>> std_notation(0.100000099999, 3)
'0.100' # good

Values less than 1 that get rounded up appear to be given an extra digit of precision. This seems to be because the calculation for 'power' in _number_profile() yields a value that is too big by 1 in these cases.

This seems to have other consequences as well:

>>> sci_notation(1.00000,3)
'1.00e0'
>>> sci_notation(0.9999,3)
'10.00e-1'

The same issue seems to exist symmetrically for negative numbers. I don't have a mathematically elegant solution, but conditionally decrementing power before determining sig_digits at the end of _number_profile() seems to work, e.g.:

    power = -1 * floor(log10(value)) + precision - 1
    if abs(value) < 1 and (floor(log10(int(round(abs(value) * 10.0**power)))) > floor(log10(int(abs(value) * 10.0**power)))):
        power -= 1
    sig_digits = str(int(round(abs(value) * 10.0**power)))

Cheers,
Tom

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.