string_conv.h File Reference


Detailed Description

Various string conversion functions.

Definition in file string_conv.h.

#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <o2scl/lib_settings.h>
#include <gsl/gsl_ieee_utils.h>

Go to the source code of this file.

Functions

std::string ptos (void *p)
 Convert a pointer to a string.
std::string itos (int x)
 Convert an integer to a string.
std::string dtos (double x, int prec=6, bool auto_prec=false)
 Convert a double to a string.
size_t size_of_exponent (double x)
 Returns the number of characters required to display the exponent of x in scientific mode.
std::string dtos (double x, std::ostream &format)
 Convert a double to a string using a specified format.
int stoi (std::string s)
 Convert a string to an integer.
double stod (std::string s)
 Convert a string to a double.
std::string double_to_latex (double x, int sigfigs=5, int ex_min=-2, int ex_max=3)
 Convert a double to a Latex-like string.
std::string double_to_html (double x, int sigfigs=5, int ex_min=-2, int ex_max=3)
 Convert a double to a HTML-like string.
std::string double_to_ieee_string (double *x)
 Convert a double to a string containing IEEE representation.


Function Documentation

std::string double_to_html ( double  x,
int  sigfigs = 5,
int  ex_min = -2,
int  ex_max = 3 
)

Convert a double to a HTML-like string.

This uses &times; and to convert a double to a string for use on the web.

The parameter sigfigs is the number of significant figures to give in the string. The parameters ex_min and ex_max represent the base-10 logarithm of the smallest and largest numbers to be represented without exponential notation. The number zero is always converted to "0". Superscripts are implemented using (can't use greater than size in documentation)

Note that this function does not warn the user if the number of significant figures requested is larger than the machine precision.

std::string double_to_ieee_string ( double *  x  ) 

Convert a double to a string containing IEEE representation.

Modeled after the GSL function gsl_ieee_fprintf_double(), but converts to a string instead of a FILE *.

std::string double_to_latex ( double  x,
int  sigfigs = 5,
int  ex_min = -2,
int  ex_max = 3 
)

Convert a double to a Latex-like string.

The parameter sigfigs is the number of significant figures to give in the string. The parameters ex_min and ex_max represent the base-10 logarithm of the smallest and largest numbers to be represented without the string

      $\times 10^{\mathrm{ex}}$
      
where ex is the relevant exponent. The number zero is always converted to "0".

Note that this function does not warn the user if the number of significant figures requested is larger than the machine precision.

Todo:
Fix to ensure final zeros are printed properly if requested

std::string dtos ( double  x,
std::ostream &  format 
)

Convert a double to a string using a specified format.

Todo:
Add error checking to this function using if(strout << x)

std::string ptos ( void *  p  ) 

Convert a pointer to a string.

This uses an ostringstream to convert a pointer to a string and is architecture-dependent.

size_t size_of_exponent ( double  x  ) 

Returns the number of characters required to display the exponent of x in scientific mode.

This usually returns 2 or 3, depending on whether or not the absolute magnitude of the exponent is greater than 100.

double stod ( std::string  s  ) 

Convert a string to a double.

If this function fails it will call set_err() and return zero.

int stoi ( std::string  s  ) 

Convert a string to an integer.

If this function fails it will call set_err() and return zero.


Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page