summaryrefslogtreecommitdiff
path: root/tests/cpp/include/variables/011-012-value-casting-operators.h
blob: 2d791b22000156f2bd77eec7cdada17ac88145c2 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
 *
 *  Test variables
 *	011-value-casting-operators.phpt
 *	012-value-casting-operators-double.phpt
 *
 */



/**
 *  Set up namespace
 */
namespace TestVariables {

	/*
	* Test Php::Value casting operators
	*/
	void value_casting(Php::Parameters &params)
	{
		Php::Value value = params[0];

		int64_t value1 = value;
		std::string value2 = value;
		bool value4 = value;

		Php::out << "   long:" << value1 << "\n string:" << value2 << "\n   bool:" << bool2str(value4) << std::endl;
	}


	/*
	* Test Php::Value casting operators
	*/
	void value_cast2double(Php::Parameters &params)
	{
		Php::Value value = params[0];
		double value3 = value;

		/*
		 * The remark (from valmat).
		 * Somehow std::to_string truncates the tail of numbers of type `double` when converting it to a string.
		 * So I wrote my own function `double2str()`, which does not have this drawback.
		 */
		Php::out << double2str(value3) << std::endl;
	}


/**
 *  End of namespace
 */
}