-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_to_string_128.cpp
More file actions
43 lines (32 loc) · 1.37 KB
/
Copy pathdemo_to_string_128.cpp
File metadata and controls
43 lines (32 loc) · 1.37 KB
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
/* file: src/demo_to_string_128.cpp
$ icp canister call demo demo_to_string_128 '()' --environment local
...nothing is printed here
-> check the console of the local network. The canister will print:
[Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] v1 =101
[Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] v2 =102
[Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] v3 =-103
-> when deployed to IC's mainnet, nothing is printed.
*/
#include "demo_to_string_128.h"
#include <iostream>
#include <optional>
#include <string>
#include "ic_api.h"
void demo_to_string_128() {
IC_API ic_api(CanisterQuery{std::string(__func__)}, false);
CandidTypePrincipal caller = ic_api.get_caller();
// -------------------------------------------------------------------------
// Numbers smaller than uint64_t & int64_t can be initialized with a literal
__uint128_t v1{101};
__int128_t v2{102};
__int128_t v3{-103};
// To create a string, use the IC_API utility method `to_string_128`
std::cout << "v1 =" + IC_API::to_string_128(v1) << std::endl;
std::cout << "v2 =" + IC_API::to_string_128(v2) << std::endl;
std::cout << "v3 =" + IC_API::to_string_128(v3) << std::endl;
// ----------------------------------------------------------------------------
// Numbers larger than uint64_t & int64_t can NOT be initialized with a literal
// See `demo_string_to_int128.cpp`
ic_api.from_wire();
ic_api.to_wire();
}