Commit Graph

19 Commits (34286dbecdb339569d8e80c568dba31bfe9e3bc7)

Author SHA1 Message Date
Ben Moon 98a43daef8 Fix rounding issue
Using `sprintf` was causing rounding to ~ 5 dp, definitely not what
we want!

Using Math::BigFloat should be fine, as styling numbers should not occur
en masse - only during conversions to/from user input.
2016-01-13 21:17:59 +00:00
Matt Miller fe1729edf1 Calculator: add structured answer. 2014-11-15 21:35:39 +02:00
Matt Miller 9fa8c14464 NumberStyler: allow for space and underscore separation.
This allows people to enter numbers in a more visually kind way,
without breaking the general paradigm.
2014-11-14 00:01:15 +02:00
Matt Miller a7ac3c7b27 NumberStyle: do not automatically convert numbers with_html.
In some cases, we have numbers which are _already_ in the appropriate
style. Most notably, when considering the user input values from which we
made the style determinations in the first place.

This fixes the bug, but is still unsatisfying because we would need
to convert both in and out in order to do better input styling.
2014-10-15 11:40:11 +02:00
Matt Miller 5481cf4ebc Fix minor code layout issues.
Reducing scroll spam from dzil by:

- Providing ABSTRACTs for all packages.
- Leaving VERSION vertical space where necessary.

Addresses #600 plus other annoyances in the process.
2014-08-20 14:45:33 -04:00
Matt Miller d23e695d36 NumberStyle: use match count for commify.
THis makes it easier for the casual reader to understand.  Thanks to
@jagtalon for the suggestion.
2014-08-06 16:53:19 -04:00
Matt Miller f909cfcd28 NumberStyle: add comment for with_html.
A bit of description as to what it is doing.
2014-08-06 14:08:46 -04:00
Matt Miller d0deb10c9e NumberStyle: default exponential to 'e'.
It's quite possible that this will never change, so o ahead and set the
efault so we don't need to specify it everywhere.
2014-08-06 14:06:27 -04:00
Rob Emery 4bbe139964 Merge branch 'mintsoft/conversion_calcs' of github.com:duckduckgo/zeroclickinfo-goodies into mintsoft/conversion_calcs
Conflicts:
	lib/DDG/GoodieRole/NumberStyle.pm
2014-08-01 23:35:39 +01:00
Matt Miller 1ad7f82e06 NumberStyle: more hackiness for negative numbers.
Basically, we're only going to recognize negative numbers when they
appear at the beginning of an expression.  Otherwise we assume we don't
needs to deal with them.

I'm sure this causes other problems, but resovles the testing issues for
now.
2014-07-31 15:36:57 -04:00
Matt Miller 2cb8d921e3 NumberStyle: only allow negative numbers at start.
This allows for us to continue to style negative numbers, but to assume
that "embedded" `-` characters are atually operations.

It's quite an ugly hack.. and this whole quasi-state machine needs
revisited, but this gets everything working for now.
2014-07-31 15:27:56 -04:00
Matt Miller 2e8b6e4316 NumberStyle: allow for negative numbers.
By extension, this also permits negative exponents.

Also breaks a calculator test with a crazy expression where we can't
differentiate between subtrction and negative numbers.  Leaving it
broken for now, since the tokenizing is known broken, anyway.
2014-07-28 10:17:17 +08:00
Matt Miller cabd9c8c8a NumberStyle: add with_html method.
This also required some additional changes to how number_regex is
computed.  That was sort of overdue, anyway.

HTML styling is simply display styling plus super-scripted exponents, at
thispoint.
2014-07-28 09:24:40 +08:00
Matt Miller 65d6f76978 NumberStyle: tighten up check for exponentials.
Also, some adjustments to Calculator to allow its tests to pass.
Still clearly not properly factored, but at least everything "works"
for the moment.
2014-07-27 22:23:04 +08:00
Matt Miller f4a7c0c857 NumberStyle: add rudimentary support for exponentials.
Also, minor updates to Conversions to make it work there.

NB: This is clearly not properly factored, yet! This is the first step
to get feedback and improvements from @mintsoft.

- Make number style stuff aware of how to deal with case-insensitive
  expoentials.
- Produce consistent output of such strings.

The display format was chosen to be consistent with the output for
Calculator.  Also, the parsing is not quite correct as you can't have a
mantissa in the exponent, but this won't catch that.

Should we also do "for_display" on the factors for consistency?

Any and all feedback or improvements are appreciated.

This also breaks the Calculator tests, but I will worry about fixing
those once everything stabilizes.
2014-07-27 20:58:05 +08:00
Matt Miller 527889dbc3 NumberStyle: another pass at improving `understands` comments.
Based primarily on feedback from @moollaza:

- Straighten up the English a bit to make it more comprehensible.
- Move comments before the code they describe.
2014-06-30 07:06:24 +08:00
Matt Miller b2071e6d3b NumberStyle: improve documentation of the `understands` logic.
Updates to comments only (plus a little layout to make it flow better),
based on feedback from @moollaza
2014-06-29 20:38:32 +08:00
Matt Miller dee4314b42 NumberStyle: minimal changes for Conversions.
I am not claiming this is entirely the correct way to do this in this
package, just that it works fairly easily to expand the scope of the
Conversions goodie, as well.

Gonna need feedback from @moollaza and @mintsoft.

On the upside, I found a bug in the styler code by writing a test here!
2014-06-28 04:27:57 +08:00
Matt Miller cd1d480294 NumberStyler: add proof-of-concept
Considering how all of this works, I'm not sure roles are quite the
right fit. It seems like we might just want a shared "Utility" package
or namespace to let us have access to some common library functions.

DDG::GoodieRole::NumberStyle is a particularly horrible name because
it's not even a role!

Also, the comments suck.

But such is the nature of a proof-of-concept.
2014-06-28 04:27:57 +08:00