# [C++ Cookbook by Jeff Cogswell] Parsing a String Containing a Number in Scientific Notation

## Problem

You have a string containing a number in scientific notation, and you want to store the number’s value in a `double` variable.

## Solution

The most direct way to parse a scientific notation number is by using the C++ library’s built-in `stringstream` class declared in `<sstream>`, as you can see in Example 3-7.

Example 3-7. Parsing a number in scientific notation

```#include <iostream>
#include <sstream>
#include <string>

using namespace std;

double sciToDub(const string& str) {

stringstream ss(str);
double d = 0;
ss >> d;

if (ss.fail()) {
string s = "Unable to format ";
s += str;
s += " as a number!";
throw (s);
}

return (d);
}

int main() {

try {
cout << sciToDub("1.234e5") << endl;
cout << sciToDub("6.02e-2") << endl;
cout << sciToDub("asdf") << endl;
}
catch (string& e) {
cerr << "Whoops: " << e << endl;
}
}```

Following is the output from this code:

```123400
0.0602
Whoops: Unable to format asdf as a number!```

https://www.safaribooksonline.com/library/view/c-cookbook/0596007612/ch03s06.html

# Latex: Strikethrough text

with the `ulem` package this becomes:

``````\usepackage[normalem]{ulem}
\sout{Hello World}``````

With the `soul` package this is:

``````\usepackage{soul}
\st{Hellow world}``````

https://tex.stackexchange.com/a/23712

# Reset GPU device and clear its memory

```g = gpuDevice(1);
M = gpuArray(magic(4));
M  % Display gpuArray```
```reset(g);
g   % Show that the device is still selected```

# Disable or increase WDDM TDR Delay

Since you’re running on windows, this may be nothing more than you hitting the windows TDR mechanism. Kernels that run longer than about 2 seconds on windows may trigger the TDR mechanism. Usually when this happens, you will see the screen flash to black and then repaint itself, as the GPU goes through the windows-triggered reset. You may also see a systray message. The exact behavior may also be different if you are running the code from within VS versus running from the command line.

Refer to the above link or search on the CUDA tag for how to modify the TDR mechanism.

Windows WDDM Driver Timeout Detection and Recovery mechanism can be disabled or the timeout can be extended to be greater than the default 2 seconds.Timeout Detection and Recovery is documented on MSDN.

Nsight Visual Studio Edition Nsight.Monitor has settings to disable or increase the timeout. Otherwise, you can use the registry keys in the MSDN article. Make sure to restart the computer after making changes.

I recommend that you increase TdrDelay before completely disabling TDR.

Tesla GPUs can use the Tesla Compute Cluster driver which does not have a timeout watchdog.

https://stackoverflow.com/a/13185441/4862158

# Matlab: Extract numbers from a mixed string

teststr = ‘Test setup: MaxDistance = 60 m, Rate = 1.000, Permitted Error = 50 Operator Note: Air Temperature=20 C, Wind Speed 16.375m/s, Altitude 5km (Cloudy)’;
regexp(teststr,[\d])
regexp(teststr,[‘\d’])
regexp(teststr,[‘\d’],’match’)
regexp(teststr,[‘\d+’],’match’)
regexp(teststr,[‘\d+.?’],’match’)
regexp(teststr,[‘\d+\.?’],’match’)
regexp(teststr,[‘\d+\.?\d?’],’match’)
regexp(teststr,[‘\d+\.?\d+?’],’match’)
regexp(teststr,[‘\d+\.?\d*?’],’match’)
regexp(teststr,[‘\d+\.?\d?’],’match’)
regexp(teststr,[‘\d+\.?\d*’],’match’)

4. Add your relative path there (relative to vcproj folder) i.e. ..\some-framework\lib by appending `PATH=%PATH%;\$(ProjectDir)\some-framework\lib` or prepending to the path `PATH=C:\some-framework\lib;%PATH%`