Program options default has unreasonable precision

Open
#85 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
cli

Research direction

Start by reproducing the formatting with the shown Boost.Program_options configuration and inspect how default_value formats a double for the displayed option description. Compare the behavior with ldecimal.cpp in the linked bezitopo project, while preserving the requested 0.1 form rather than .1. Done means the default is displayed as (=0.1) without breaking other option output.

Written by the indexing model from the issue text.

Description

Source code:

  time_t now,then;
  double tolerance,stageTolerance,areadone,rmsadj;
  bool done=false;
  string inputFile,outputFile;
  bool validArgs,validCmd=true;
  po::options_description generic("Options");
  po::options_description hidden("Hidden options");
  po::options_description cmdline_options;
  po::positional_options_description p;
  po::variables_map vm;
  generic.add_options()
    ("tolerance,t",po::value<double>(&tolerance)->default_value(0.1),"Vertical tolerance")
    ("output,o",po::value<string>(&outputFile),"Output file");
  hidden.add_options()
    ("input",po::value<string>(&inputFile),"Input file");
  p.add("input",1);
  cmdline_options.add(generic).add(hidden);
//...
      cout<<generic;

Output:

  -t [ --tolerance ] arg (=0.10000000000000001)
                                        Vertical tolerance
  -o [ --output ] arg                   Output file

Output should be:

  -t [ --tolerance ] arg (=0.1)         Vertical tolerance
  -o [ --output ] arg                   Output file

I've tried this on Boost 1.65.1 on Ubuntu Beaver, and Boost 1.69.0 on DragonFly BSD 5.5, and got the same result.

For an idea on how to fix it, see ldecimal.cpp in https://github.com/phma/bezitopo, but that would output ".1", not "0.1".

Dominant language
C++
Stars
136
Forks
117
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/program_options

All issues in boostorg/program_options

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.