Fixed Point Number IO
Standard Stream I/O
EirinFixed provides a simple interface for input and output of fixed point numbers using standard C++ streams. You can use the standard input and output streams to read and write fixed point numbers. For example, you can use the following code to read a fixed point number from standard input and print it to standard output:
#include <iostream>
#include <eirin/fixed.hpp>
int main() {
using namespace eirin;
// Read a fixed point number from standard input
fixed64 x;
std::cin >> x;
// Print the fixed point number to standard output
std::cout << "The fixed point number is: " << x << std::endl;
return 0;
}
Other I/O Libraries
You can use the format functions provided by [Papilio Charontis](https://github.com/HenryAWE/PapilioCharontis).
When using Papilio Charontis, please make sure you have include the
ext/papilio_integration.hppheader file.The default format is
{}, which will print the fixed point number in decimal format.For other format arguments, you should branch it with
{:}and use the format specifier as you would in C++. For example, you can use{:x}to print the fixed point number in hexadecimal format.Some arguments will override other format arguments declared before. To illustrate this, the following table shows the format arguments, and the
Conflictcolumn shows the format arguments that will be overridden by the current format argument.When radix argument is specified, only the integral part will be printed.
Format |
Description |
Conflict |
Note |
|---|---|---|---|
|
This will print the internal value of the fixed point number in hexadecimal format. |
NO CONFLICT |
No need to note. |
|
Specify the radix prefix. |
NO CONFLICT |
This will only works with radix arguments. |
|
This will print the fixed point number in hexadecimal format, with lowercase letters. |
|
The |
|
This will print the fixed point number in hexadecimal format, with uppercase letters. |
|
The |
|
This will print the fixed point number in decimal format. |
|
The prefix of decimal will never be added, for no need. |
|
This will print the fixed point number in binary format. |
|
The |
|
This will print the fixed point number in octal format. |
|
The prefix will only be added with |
#include <iostream>
#include <eirin/fixed.hpp>
#include <eirin/ext/papilio_integration.hpp>
int main() {
using namespace eirin;
fixed64 x = 114.514_f64;
papilio::println("fixed number: {}", x);
papilio::println("fixed number internal value: {:?}", x);
return 0;
}
Builtin Input/Output
There are two builtin input functions, f32_from_cstring, and fixed_from_cstring.