File: lambert_w_basic_example.cpp

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (30 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright Paul A. Bristow 2018

// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

// Example of most basic call of both lambert W functions.
// Only requires C++03 
// (and optionally a call of max_digits10 to show precision).

#include <boost/math/special_functions/lambert_w.hpp> // For lambert_w0 and wm1 functions.

#include <iostream>
#include <iomanip>

int main()
{
  double z = 2.0;
  double w0 = boost::math::lambert_w0(z);
  std::cout.setf(std::ios_base::showpoint); // Include any trailing zeros.
  std::cout.precision(std::numeric_limits<double>::max_digits10); // Show all possibly significant digits.
  // Avoid using max_digfigs10 so as many old compilers can run the most basic lambert_w0 test?
  // Require to get max_digits10
  //   [ run lambert_w_basic_example.cpp  : : : [ requires cxx11_numeric_limits ] ]
  std::cout << " lambert_w0(" << z << ") = " << w0 << std::endl; // lambert_w0(2.00000) = 0.852606
  z = -0.2;
  double wm1 = boost::math::lambert_wm1(z);
  std::cout << " lambert_wm1(" << z << ") = " << wm1 << std::endl; // lambert_wm1(-0.200000) = -2.54264
  return 0;
} // int main()