Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 046655c57f63
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 562e174ec31f
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Oct 11, 2020

  1. Copy the full SHA
    562e174 View commit details
Showing with 12 additions and 6 deletions.
  1. +12 −6 scopehal/Unit.cpp
18 changes: 12 additions & 6 deletions scopehal/Unit.cpp
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ string Unit::PrettyPrint(double value)
scale = "p";
}

bool space_after_number = true;
switch(m_type)
{
//Special handling needed since it's not a SI base unit
@@ -142,7 +143,8 @@ string Unit::PrettyPrint(double value)
unit = "bps";
break;
case UNIT_UI:
unit = "UI";
unit = " UI"; //move the space next to the number
space_after_number = false;
break;
case UNIT_RPM:
unit = "RPM";
@@ -199,18 +201,22 @@ string Unit::PrettyPrint(double value)

default:
{
const char* space = " ";
if(!space_after_number)
space = "";

//If not a round number, add more digits (up to 4)
//TODO: allow user to specify how many sigfigs they want
if( fabs(round(value_rescaled) - value_rescaled) < 0.001 )
snprintf(tmp, sizeof(tmp), "%.0f %s%s", value_rescaled, scale, unit);
snprintf(tmp, sizeof(tmp), "%.0f%s%s%s", value_rescaled, space, scale, unit);
else if(fabs(round(value_rescaled*10) - value_rescaled*10) < 0.001)
snprintf(tmp, sizeof(tmp), "%.1f %s%s", value_rescaled, scale, unit);
snprintf(tmp, sizeof(tmp), "%.1f%s%s%s", value_rescaled, space, scale, unit);
else if(fabs(round(value_rescaled*100) - value_rescaled*100) < 0.001 )
snprintf(tmp, sizeof(tmp), "%.2f %s%s", value_rescaled, scale, unit);
snprintf(tmp, sizeof(tmp), "%.2f%s%s%s", value_rescaled, space, scale, unit);
else if(fabs(round(value_rescaled*1000) - value_rescaled*1000) < 0.001 )
snprintf(tmp, sizeof(tmp), "%.3f %s%s", value_rescaled, scale, unit);
snprintf(tmp, sizeof(tmp), "%.3f%s%s%s", value_rescaled, space, scale, unit);
else
snprintf(tmp, sizeof(tmp), "%.4f %s%s", value_rescaled, scale, unit);
snprintf(tmp, sizeof(tmp), "%.4f%s%s%s", value_rescaled, space, scale, unit);
}
break;
}