Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Information addition not always works as expected. #324

Open
atk91 opened this issue Nov 23, 2018 · 1 comment
Open

Information addition not always works as expected. #324

atk91 opened this issue Nov 23, 2018 · 1 comment

Comments

@atk91
Copy link

atk91 commented Nov 23, 2018

Bytes(Double.MaxValue / 2.0) == (Bytes(Double.MaxValue / 2.0) + Bytes(1.0)) will evaluate to true
This happens because Information's underlying type is Double. Not sure about reasons to choose this, it seems that Long should suit these needs better.

@hunterpayne
Copy link
Contributor

  1. Change the args to Information like so

final class Information private(val amount: Long, val unit: InformationUnit)
extends Quantity[Information]
with TimeIntegral[DataRate] {

  1. Add this to the Information class as well:
    def value = amount.toDouble

// overridden to remove the forcing of doubles for this unit that makes
// no sense now that this dimension is represented by a long
override def toString(): String = s"$amount ${unit.symbol}"
override def toString(uom: UnitOfMeasure[Information]): String =
in(uom).toString()

  1. In the Information object: change the first apply method like so (toDouble becomes toLong):
    private[information] def apply[A](n: A, unit: InformationUnit)(implicit num: Numeric[A]) = new Information(num.toLong(n), unit)

  2. Change the InformationSpec test to remove the .0 from the expected strings in the string formatting test

Go ahead and make that PR for yourself and push it back...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants