squants icon indicating copy to clipboard operation
squants copied to clipboard

Information addition not always works as expected.

Open atk91 opened this issue 7 years ago • 1 comments

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.

atk91 avatar Nov 23 '18 16:11 atk91

  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...

hunterpayne avatar Jan 19 '19 10:01 hunterpayne