go_engine/std/
bits.rs

1// Copyright 2022 The Goscript Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5extern crate self as go_engine;
6use crate::ffi::*;
7use go_vm::types::*;
8
9#[derive(Ffi)]
10pub struct BitsFfi;
11
12#[ffi_impl]
13impl BitsFfi {
14    fn ffi_f32_to_bits(f: f32) -> u32 {
15        u32::from_be_bytes(f.to_be_bytes())
16    }
17
18    fn ffi_f32_from_bits(u: u32) -> f32 {
19        f32::from_be_bytes(u.to_be_bytes())
20    }
21
22    fn ffi_f64_to_bits(f: f64) -> u64 {
23        u64::from_be_bytes(f.to_be_bytes())
24    }
25
26    fn ffi_f64_from_bits(u: u64) -> f64 {
27        f64::from_be_bytes(u.to_be_bytes())
28    }
29}