| 1 |
import wasm from "./diplomat-wasm.mjs" |
| 2 |
import * as diplomatRuntime from "./diplomat-runtime.mjs" |
| 3 |
import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs" |
| 4 |
import { ICU4XFixedDecimalSign_js_to_rust, ICU4XFixedDecimalSign_rust_to_js } from "./ICU4XFixedDecimalSign.mjs" |
| 5 |
import { ICU4XFixedDecimalSignDisplay_js_to_rust, ICU4XFixedDecimalSignDisplay_rust_to_js } from "./ICU4XFixedDecimalSignDisplay.mjs" |
| 6 |
import { ICU4XRoundingIncrement_js_to_rust, ICU4XRoundingIncrement_rust_to_js } from "./ICU4XRoundingIncrement.mjs" |
| 7 |
|
| 8 |
const ICU4XFixedDecimal_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 9 |
wasm.ICU4XFixedDecimal_destroy(underlying); |
| 10 |
}); |
| 11 |
|
| 12 |
export class ICU4XFixedDecimal { |
| 13 |
#lifetimeEdges = []; |
| 14 |
constructor(underlying, owned, edges) { |
| 15 |
this.underlying = underlying; |
| 16 |
this.#lifetimeEdges.push(...edges); |
| 17 |
if (owned) { |
| 18 |
ICU4XFixedDecimal_box_destroy_registry.register(this, underlying); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
static create_from_i32(arg_v) { |
| 23 |
return new ICU4XFixedDecimal(wasm.ICU4XFixedDecimal_create_from_i32(arg_v), true, []); |
| 24 |
} |
| 25 |
|
| 26 |
static create_from_u32(arg_v) { |
| 27 |
return new ICU4XFixedDecimal(wasm.ICU4XFixedDecimal_create_from_u32(arg_v), true, []); |
| 28 |
} |
| 29 |
|
| 30 |
static create_from_i64(arg_v) { |
| 31 |
return new ICU4XFixedDecimal(wasm.ICU4XFixedDecimal_create_from_i64(arg_v), true, []); |
| 32 |
} |
| 33 |
|
| 34 |
static create_from_u64(arg_v) { |
| 35 |
return new ICU4XFixedDecimal(wasm.ICU4XFixedDecimal_create_from_u64(arg_v), true, []); |
| 36 |
} |
| 37 |
|
| 38 |
static create_from_f64_with_integer_precision(arg_f) { |
| 39 |
return (() => { |
| 40 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 41 |
wasm.ICU4XFixedDecimal_create_from_f64_with_integer_precision(diplomat_receive_buffer, arg_f); |
| 42 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 43 |
if (is_ok) { |
| 44 |
const ok_value = new ICU4XFixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 45 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 46 |
return ok_value; |
| 47 |
} else { |
| 48 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 49 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 50 |
throw new diplomatRuntime.FFIError(throw_value); |
| 51 |
} |
| 52 |
})(); |
| 53 |
} |
| 54 |
|
| 55 |
static create_from_f64_with_lower_magnitude(arg_f, arg_magnitude) { |
| 56 |
return (() => { |
| 57 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 58 |
wasm.ICU4XFixedDecimal_create_from_f64_with_lower_magnitude(diplomat_receive_buffer, arg_f, arg_magnitude); |
| 59 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 60 |
if (is_ok) { |
| 61 |
const ok_value = new ICU4XFixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 62 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 63 |
return ok_value; |
| 64 |
} else { |
| 65 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 66 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 67 |
throw new diplomatRuntime.FFIError(throw_value); |
| 68 |
} |
| 69 |
})(); |
| 70 |
} |
| 71 |
|
| 72 |
static create_from_f64_with_significant_digits(arg_f, arg_digits) { |
| 73 |
return (() => { |
| 74 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 75 |
wasm.ICU4XFixedDecimal_create_from_f64_with_significant_digits(diplomat_receive_buffer, arg_f, arg_digits); |
| 76 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 77 |
if (is_ok) { |
| 78 |
const ok_value = new ICU4XFixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 79 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 80 |
return ok_value; |
| 81 |
} else { |
| 82 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 83 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 84 |
throw new diplomatRuntime.FFIError(throw_value); |
| 85 |
} |
| 86 |
})(); |
| 87 |
} |
| 88 |
|
| 89 |
static create_from_f64_with_floating_precision(arg_f) { |
| 90 |
return (() => { |
| 91 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 92 |
wasm.ICU4XFixedDecimal_create_from_f64_with_floating_precision(diplomat_receive_buffer, arg_f); |
| 93 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 94 |
if (is_ok) { |
| 95 |
const ok_value = new ICU4XFixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 96 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 97 |
return ok_value; |
| 98 |
} else { |
| 99 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 100 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 101 |
throw new diplomatRuntime.FFIError(throw_value); |
| 102 |
} |
| 103 |
})(); |
| 104 |
} |
| 105 |
|
| 106 |
static create_from_string(arg_v) { |
| 107 |
const buf_arg_v = diplomatRuntime.DiplomatBuf.str8(wasm, arg_v); |
| 108 |
const diplomat_out = (() => { |
| 109 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 110 |
wasm.ICU4XFixedDecimal_create_from_string(diplomat_receive_buffer, buf_arg_v.ptr, buf_arg_v.size); |
| 111 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 112 |
if (is_ok) { |
| 113 |
const ok_value = new ICU4XFixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 114 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 115 |
return ok_value; |
| 116 |
} else { |
| 117 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 118 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 119 |
throw new diplomatRuntime.FFIError(throw_value); |
| 120 |
} |
| 121 |
})(); |
| 122 |
buf_arg_v.free(); |
| 123 |
return diplomat_out; |
| 124 |
} |
| 125 |
|
| 126 |
digit_at(arg_magnitude) { |
| 127 |
return wasm.ICU4XFixedDecimal_digit_at(this.underlying, arg_magnitude); |
| 128 |
} |
| 129 |
|
| 130 |
magnitude_start() { |
| 131 |
return wasm.ICU4XFixedDecimal_magnitude_start(this.underlying); |
| 132 |
} |
| 133 |
|
| 134 |
magnitude_end() { |
| 135 |
return wasm.ICU4XFixedDecimal_magnitude_end(this.underlying); |
| 136 |
} |
| 137 |
|
| 138 |
nonzero_magnitude_start() { |
| 139 |
return wasm.ICU4XFixedDecimal_nonzero_magnitude_start(this.underlying); |
| 140 |
} |
| 141 |
|
| 142 |
nonzero_magnitude_end() { |
| 143 |
return wasm.ICU4XFixedDecimal_nonzero_magnitude_end(this.underlying); |
| 144 |
} |
| 145 |
|
| 146 |
is_zero() { |
| 147 |
return wasm.ICU4XFixedDecimal_is_zero(this.underlying); |
| 148 |
} |
| 149 |
|
| 150 |
multiply_pow10(arg_power) { |
| 151 |
wasm.ICU4XFixedDecimal_multiply_pow10(this.underlying, arg_power); |
| 152 |
} |
| 153 |
|
| 154 |
sign() { |
| 155 |
return ICU4XFixedDecimalSign_rust_to_js[wasm.ICU4XFixedDecimal_sign(this.underlying)]; |
| 156 |
} |
| 157 |
|
| 158 |
set_sign(arg_sign) { |
| 159 |
wasm.ICU4XFixedDecimal_set_sign(this.underlying, ICU4XFixedDecimalSign_js_to_rust[arg_sign]); |
| 160 |
} |
| 161 |
|
| 162 |
apply_sign_display(arg_sign_display) { |
| 163 |
wasm.ICU4XFixedDecimal_apply_sign_display(this.underlying, ICU4XFixedDecimalSignDisplay_js_to_rust[arg_sign_display]); |
| 164 |
} |
| 165 |
|
| 166 |
trim_start() { |
| 167 |
wasm.ICU4XFixedDecimal_trim_start(this.underlying); |
| 168 |
} |
| 169 |
|
| 170 |
trim_end() { |
| 171 |
wasm.ICU4XFixedDecimal_trim_end(this.underlying); |
| 172 |
} |
| 173 |
|
| 174 |
pad_start(arg_position) { |
| 175 |
wasm.ICU4XFixedDecimal_pad_start(this.underlying, arg_position); |
| 176 |
} |
| 177 |
|
| 178 |
pad_end(arg_position) { |
| 179 |
wasm.ICU4XFixedDecimal_pad_end(this.underlying, arg_position); |
| 180 |
} |
| 181 |
|
| 182 |
set_max_position(arg_position) { |
| 183 |
wasm.ICU4XFixedDecimal_set_max_position(this.underlying, arg_position); |
| 184 |
} |
| 185 |
|
| 186 |
trunc(arg_position) { |
| 187 |
wasm.ICU4XFixedDecimal_trunc(this.underlying, arg_position); |
| 188 |
} |
| 189 |
|
| 190 |
trunc_to_increment(arg_position, arg_increment) { |
| 191 |
wasm.ICU4XFixedDecimal_trunc_to_increment(this.underlying, arg_position, ICU4XRoundingIncrement_js_to_rust[arg_increment]); |
| 192 |
} |
| 193 |
|
| 194 |
half_trunc(arg_position) { |
| 195 |
wasm.ICU4XFixedDecimal_half_trunc(this.underlying, arg_position); |
| 196 |
} |
| 197 |
|
| 198 |
half_trunc_to_increment(arg_position, arg_increment) { |
| 199 |
wasm.ICU4XFixedDecimal_half_trunc_to_increment(this.underlying, arg_position, ICU4XRoundingIncrement_js_to_rust[arg_increment]); |
| 200 |
} |
| 201 |
|
| 202 |
expand(arg_position) { |
| 203 |
wasm.ICU4XFixedDecimal_expand(this.underlying, arg_position); |
| 204 |
} |
| 205 |
|
| 206 |
expand_to_increment(arg_position, arg_increment) { |
| 207 |
wasm.ICU4XFixedDecimal_expand_to_increment(this.underlying, arg_position, ICU4XRoundingIncrement_js_to_rust[arg_increment]); |
| 208 |
} |
| 209 |
|
| 210 |
half_expand(arg_position) { |
| 211 |
wasm.ICU4XFixedDecimal_half_expand(this.underlying, arg_position); |
| 212 |
} |
| 213 |
|
| 214 |
half_expand_to_increment(arg_position, arg_increment) { |
| 215 |
wasm.ICU4XFixedDecimal_half_expand_to_increment(this.underlying, arg_position, ICU4XRoundingIncrement_js_to_rust[arg_increment]); |
| 216 |
} |
| 217 |
|
| 218 |
ceil(arg_position) { |
| 219 |
wasm.ICU4XFixedDecimal_ceil(this.underlying, arg_position); |
| 220 |
} |
| 221 |
|
| 222 |
ceil_to_increment(arg_position, arg_increment) { |
| 223 |
wasm.ICU4XFixedDecimal_ceil_to_increment(this.underlying, arg_position, ICU4XRoundingIncrement_js_to_rust[arg_increment]); |
| 224 |
} |
| 225 |
|
| 226 |
half_ceil(arg_position) { |
| 227 |
wasm.ICU4XFixedDecimal_half_ceil(this.underlying, arg_position); |
| 228 |
} |
| 229 |
|
| 230 |
half_ceil_to_increment(arg_position, arg_increment) { |
| 231 |
wasm.ICU4XFixedDecimal_half_ceil_to_increment(this.underlying, arg_position, ICU4XRoundingIncrement_js_to_rust[arg_increment]); |
| 232 |
} |
| 233 |
|
| 234 |
floor(arg_position) { |
| 235 |
wasm.ICU4XFixedDecimal_floor(this.underlying, arg_position); |
| 236 |
} |
| 237 |
|
| 238 |
floor_to_increment(arg_position, arg_increment) { |
| 239 |
wasm.ICU4XFixedDecimal_floor_to_increment(this.underlying, arg_position, ICU4XRoundingIncrement_js_to_rust[arg_increment]); |
| 240 |
} |
| 241 |
|
| 242 |
half_floor(arg_position) { |
| 243 |
wasm.ICU4XFixedDecimal_half_floor(this.underlying, arg_position); |
| 244 |
} |
| 245 |
|
| 246 |
half_floor_to_increment(arg_position, arg_increment) { |
| 247 |
wasm.ICU4XFixedDecimal_half_floor_to_increment(this.underlying, arg_position, ICU4XRoundingIncrement_js_to_rust[arg_increment]); |
| 248 |
} |
| 249 |
|
| 250 |
half_even(arg_position) { |
| 251 |
wasm.ICU4XFixedDecimal_half_even(this.underlying, arg_position); |
| 252 |
} |
| 253 |
|
| 254 |
half_even_to_increment(arg_position, arg_increment) { |
| 255 |
wasm.ICU4XFixedDecimal_half_even_to_increment(this.underlying, arg_position, ICU4XRoundingIncrement_js_to_rust[arg_increment]); |
| 256 |
} |
| 257 |
|
| 258 |
concatenate_end(arg_other) { |
| 259 |
return (() => { |
| 260 |
const is_ok = wasm.ICU4XFixedDecimal_concatenate_end(this.underlying, arg_other.underlying) == 1; |
| 261 |
if (!is_ok) { |
| 262 |
throw new diplomatRuntime.FFIError(undefined); |
| 263 |
} |
| 264 |
})(); |
| 265 |
} |
| 266 |
|
| 267 |
to_string() { |
| 268 |
return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 269 |
return wasm.ICU4XFixedDecimal_to_string(this.underlying, writeable); |
| 270 |
}); |
| 271 |
} |
| 272 |
} |