Commit e139e659 authored by Aske Simon Christensen's avatar Aske Simon Christensen
Browse files

Use safe float transmutations from Rust 1.20

parent c5bc388b
......@@ -5,7 +5,6 @@
extern crate vst2;
use std::cmp::Ordering;
use std::mem::transmute;
use vst2::buffer::AudioBuffer;
use vst2::plugin::{Category, Info, Plugin};
......@@ -52,12 +51,12 @@ fn quantize(value: f32, level: f32) -> f32 {
let bit = 1 << ((level * 31.0).floor() as i32);
let mask = !bit + 1;
let add = bit >> 1;
let mut bits = unsafe { transmute::<f32, u32>(value) };
bits = (bits + add) & mask;
let mut bits = value.to_bits();
bits = bits.wrapping_add(add) & mask;
if bits == 0x80000000 {
bits = 0x00000000;
}
unsafe { transmute::<u32, f32>(bits) }
f32::from_bits(bits)
}
......
use std::{f32, f64};
use std::mem::transmute;
use std::ops::{Index};
#[cfg(test)] use std::collections::HashMap;
......@@ -85,12 +84,12 @@ fn quantize(value: f32, level: f32) -> f32 {
let bit = 1 << ((level * 31.0).floor() as i32);
let mask = !bit + 1;
let add = bit >> 1;
let mut bits = unsafe { transmute::<f32, u32>(value) };
let mut bits = value.to_bits();
bits = bits.wrapping_add(add) & mask;
if bits == 0x80000000 {
bits = 0x00000000;
}
unsafe { transmute::<u32, f32>(bits) }
f32::from_bits(bits)
}
#[derive(Clone, PartialEq)]
......
use std::collections::{HashMap, VecDeque};
use std::marker::PhantomData;
use std::mem::transmute;
use std::sync::RwLock;
use vst2::api::Supported;
......@@ -333,7 +332,7 @@ impl<G: SoundGenerator, S: SynthInfo> SynthPlugin<G, S> {
}
fn infinitesimal_change(value: f32) -> f32 {
let mut bits = unsafe { transmute::<f32, u32>(value) };
let mut bits = value.to_bits();
bits += 1;
unsafe { transmute::<u32, f32>(bits) }
f32::from_bits(bits)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment