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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Copyright © 2024 Mikhail Hogrefe
//
// This file is part of Malachite.
//
// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.

/// [`FromSciString`](super::traits::FromSciString), a trait for converting strings, possibly using
/// scientific notation, to numbers.
///
/// # from_sci_string
/// ```
/// use malachite_base::num::conversion::traits::FromSciString;
///
/// assert_eq!(u8::from_sci_string("123"), Some(123));
/// assert_eq!(u8::from_sci_string("123.5"), Some(124));
/// assert_eq!(u8::from_sci_string("256"), None);
/// assert_eq!(u64::from_sci_string("1.23e10"), Some(12300000000));
/// ```
///
/// # from_sci_string_with_options
/// ```
/// use malachite_base::num::conversion::string::options::FromSciStringOptions;
/// use malachite_base::num::conversion::traits::FromSciString;
/// use malachite_base::rounding_modes::RoundingMode::*;
///
/// let mut options = FromSciStringOptions::default();
/// assert_eq!(
///     u8::from_sci_string_with_options("123.5", options),
///     Some(124)
/// );
///
/// options.set_rounding_mode(Floor);
/// assert_eq!(
///     u8::from_sci_string_with_options("123.5", options),
///     Some(123)
/// );
///
/// options = FromSciStringOptions::default();
/// options.set_base(16);
/// assert_eq!(u8::from_sci_string_with_options("ff", options), Some(255));
/// ```
pub mod from_sci_string;
/// [`FromStringBase`](super::traits::FromStringBase), a trait for converting strings in a specified
/// base to numbers.
pub mod from_string;
/// [`ToSciOptions`](options::ToSciOptions) and
/// [`FromSciSringOptions`](options::FromSciStringOptions), `struct`s for specifying parameters when
/// using the [`FromSciString`](super::traits::FromSciString) and [`ToSci`](super::traits::ToSci)
/// traits.
pub mod options;
/// [`ToSci`](super::traits::ToSci), a trait for converting a number to string, possibly using
/// scientific notation.
///
/// # to_sci
/// ```
/// use malachite_base::num::conversion::traits::ToSci;
///
/// // If the value can fit in a `u32`, the result is the same as with `to_string`
/// assert_eq!(123u8.to_sci().to_string(), "123");
///
/// assert_eq!(u128::MAX.to_sci().to_string(), "3.402823669209385e38");
/// assert_eq!(i128::MIN.to_sci().to_string(), "-1.701411834604692e38");
/// ```
///
/// # to_sci_with_options
/// ```
/// use malachite_base::num::conversion::string::options::ToSciOptions;
/// use malachite_base::num::conversion::traits::ToSci;
/// use malachite_base::rounding_modes::RoundingMode::*;
///
/// let mut options = ToSciOptions::default();
/// assert_eq!(123456u32.to_sci_with_options(options).to_string(), "123456");
///
/// options.set_precision(3);
/// assert_eq!(123456u32.to_sci_with_options(options).to_string(), "1.23e5");
///
/// options.set_rounding_mode(Ceiling);
/// assert_eq!(123456u32.to_sci_with_options(options).to_string(), "1.24e5");
///
/// options.set_e_uppercase();
/// assert_eq!(123456u32.to_sci_with_options(options).to_string(), "1.24E5");
///
/// options.set_force_exponent_plus_sign(true);
/// assert_eq!(
///     123456u32.to_sci_with_options(options).to_string(),
///     "1.24E+5"
/// );
///
/// options = ToSciOptions::default();
/// options.set_base(36);
/// assert_eq!(123456u32.to_sci_with_options(options).to_string(), "2n9c");
///
/// options.set_uppercase();
/// assert_eq!(123456u32.to_sci_with_options(options).to_string(), "2N9C");
///
/// options.set_base(2);
/// options.set_precision(10);
/// assert_eq!(
///     123456u32.to_sci_with_options(options).to_string(),
///     "1.1110001e16"
/// );
///
/// options.set_include_trailing_zeros(true);
/// assert_eq!(
///     123456u32.to_sci_with_options(options).to_string(),
///     "1.111000100e16"
/// );
/// ```
///
/// # fmt_sci_valid
/// ```
/// use malachite_base::num::conversion::string::options::ToSciOptions;
/// use malachite_base::num::conversion::traits::ToSci;
/// use malachite_base::rounding_modes::RoundingMode::*;
///
/// let mut options = ToSciOptions::default();
/// assert!(123u8.fmt_sci_valid(options));
/// assert!(u128::MAX.fmt_sci_valid(options));
/// options.set_rounding_mode(Exact);
/// assert!(!u128::MAX.fmt_sci_valid(options)); // u128::MAX has more than 16 significant digits
/// options.set_precision(50);
/// assert!(u128::MAX.fmt_sci_valid(options));
/// ```
pub mod to_sci;
/// The [`BaseFmtWrapper`](to_string::BaseFmtWrapper) struct and
/// [`ToStringBase`](super::traits::ToStringBase) trait, used for converting numbers to strings.
///
/// # Display::fmt for BaseFmtWrapper
/// ```
/// use malachite_base::num::conversion::string::to_string::BaseFmtWrapper;
///
/// let x = BaseFmtWrapper::new(1000000000u32, 36);
/// assert_eq!(format!("{}", x), "gjdgxs");
/// assert_eq!(format!("{:#}", x), "GJDGXS");
/// assert_eq!(format!("{:010}", x), "0000gjdgxs");
/// assert_eq!(format!("{:#010}", x), "0000GJDGXS");
///
/// let x = BaseFmtWrapper::new(-1000000000i32, 36);
/// assert_eq!(format!("{}", x), "-gjdgxs");
/// assert_eq!(format!("{:#}", x), "-GJDGXS");
/// assert_eq!(format!("{:010}", x), "-000gjdgxs");
/// assert_eq!(format!("{:#010}", x), "-000GJDGXS");
/// ```
///
/// # Debug::fmt for BaseFmtWrapper
/// ```
/// use malachite_base::num::conversion::string::to_string::BaseFmtWrapper;
///
/// let x = BaseFmtWrapper::new(1000000000u32, 36);
/// assert_eq!(format!("{:?}", x), "gjdgxs");
/// assert_eq!(format!("{:#?}", x), "GJDGXS");
/// assert_eq!(format!("{:010?}", x), "0000gjdgxs");
/// assert_eq!(format!("{:#010?}", x), "0000GJDGXS");
///
/// let x = BaseFmtWrapper::new(-1000000000i32, 36);
/// assert_eq!(format!("{:?}", x), "-gjdgxs");
/// assert_eq!(format!("{:#?}", x), "-GJDGXS");
/// assert_eq!(format!("{:010?}", x), "-000gjdgxs");
/// assert_eq!(format!("{:#010?}", x), "-000GJDGXS");
/// ```
///
/// # to_string_base
/// ```
/// use malachite_base::num::conversion::traits::ToStringBase;
///
/// assert_eq!(1000u16.to_string_base(2), "1111101000");
/// assert_eq!(1000u16.to_string_base(10), "1000");
/// assert_eq!(1000u16.to_string_base(36), "rs");
///
/// assert_eq!(1000i16.to_string_base(2), "1111101000");
/// assert_eq!(1000i16.to_string_base(10), "1000");
/// assert_eq!(1000i16.to_string_base(36), "rs");
///
/// assert_eq!((-1000i16).to_string_base(2), "-1111101000");
/// assert_eq!((-1000i16).to_string_base(10), "-1000");
/// assert_eq!((-1000i16).to_string_base(36), "-rs");
/// ```
///
/// # to_string_base_upper
/// ```
/// use malachite_base::num::conversion::traits::ToStringBase;
///
/// assert_eq!(1000u16.to_string_base_upper(2), "1111101000");
/// assert_eq!(1000u16.to_string_base_upper(10), "1000");
/// assert_eq!(1000u16.to_string_base_upper(36), "RS");
///
/// assert_eq!(1000i16.to_string_base_upper(2), "1111101000");
/// assert_eq!(1000i16.to_string_base_upper(10), "1000");
/// assert_eq!(1000i16.to_string_base_upper(36), "RS");
///
/// assert_eq!((-1000i16).to_string_base_upper(2), "-1111101000");
/// assert_eq!((-1000i16).to_string_base_upper(10), "-1000");
/// assert_eq!((-1000i16).to_string_base_upper(36), "-RS");
/// ```
pub mod to_string;