use ffi;
pub struct RootFSolverType {
s: *mut ffi::gsl_root_fsolver_type,
}
impl ffi::FFI<ffi::gsl_root_fsolver_type> for RootFSolverType {
fn wrap(r: *mut ffi::gsl_root_fsolver_type) -> RootFSolverType {
RootFSolverType { s: r }
}
fn soft_wrap(r: *mut ffi::gsl_root_fsolver_type) -> RootFSolverType {
Self::wrap(r)
}
fn unwrap_shared(s: &RootFSolverType) -> *const ffi::gsl_root_fsolver_type {
s.s as *const _
}
fn unwrap_unique(s: &mut RootFSolverType) -> *mut ffi::gsl_root_fsolver_type {
s.s
}
}
impl RootFSolverType {
pub fn bisection() -> RootFSolverType {
RootFSolverType { s: unsafe { ffi::gsl_root_fsolver_bisection } }
}
pub fn brent() -> RootFSolverType {
RootFSolverType { s: unsafe { ffi::gsl_root_fsolver_brent } }
}
pub fn falsepos() -> RootFSolverType {
RootFSolverType { s: unsafe { ffi::gsl_root_fsolver_falsepos } }
}
}
pub use ffi::gsl_function as RootFunction;
pub struct RootFSolver {
s: *mut ffi::gsl_root_fsolver,
}
impl RootFSolver {
pub fn new(t: &RootFSolverType) -> Option<RootFSolver> {
let tmp = unsafe { ffi::gsl_root_fsolver_alloc(ffi::FFI::unwrap_shared(t)) };
if tmp.is_null() {
None
} else {
Some(RootFSolver { s: tmp })
}
}
pub fn set(&mut self, f: &mut RootFunction, x_lower: f64, x_upper: f64) -> ::Value {
::Value::from(unsafe {
ffi::gsl_root_fsolver_set(self.s, f as *mut RootFunction, x_lower, x_upper)
})
}
pub fn iterate(&mut self) -> ::Value {
::Value::from(unsafe { ffi::gsl_root_fsolver_iterate(self.s) })
}
pub fn name(&self) -> String {
unsafe {
let tmp = ffi::gsl_root_fsolver_name(self.s);
String::from_utf8_lossy(::std::ffi::CStr::from_ptr(tmp).to_bytes()).to_string()
}
}
pub fn root(&self) -> f64 {
unsafe { ffi::gsl_root_fsolver_root(self.s) }
}
pub fn x_lower(&self) -> f64 {
unsafe { ffi::gsl_root_fsolver_x_lower(self.s) }
}
pub fn x_upper(&self) -> f64 {
unsafe { ffi::gsl_root_fsolver_x_upper(self.s) }
}
}
impl Drop for RootFSolver {
fn drop(&mut self) {
if !self.s.is_null() {
unsafe {
ffi::gsl_root_fsolver_free(self.s);
}
self.s = ::std::ptr::null_mut();
}
}
}
pub struct RootFdfSolverType {
s: *mut ffi::gsl_root_fdfsolver_type,
}
impl ffi::FFI<ffi::gsl_root_fdfsolver_type> for RootFdfSolverType {
fn wrap(r: *mut ffi::gsl_root_fdfsolver_type) -> RootFdfSolverType {
RootFdfSolverType { s: r }
}
fn soft_wrap(r: *mut ffi::gsl_root_fdfsolver_type) -> RootFdfSolverType {
Self::wrap(r)
}
fn unwrap_shared(s: &RootFdfSolverType) -> *const ffi::gsl_root_fdfsolver_type {
s.s as *const _
}
fn unwrap_unique(s: &mut RootFdfSolverType) -> *mut ffi::gsl_root_fdfsolver_type {
s.s
}
}
impl RootFdfSolverType {
pub fn newton() -> RootFdfSolverType {
RootFdfSolverType { s: unsafe { ffi::gsl_root_fdfsolver_newton } }
}
pub fn secant() -> RootFdfSolverType {
RootFdfSolverType { s: unsafe { ffi::gsl_root_fdfsolver_secant } }
}
pub fn steffenson() -> RootFdfSolverType {
RootFdfSolverType { s: unsafe { ffi::gsl_root_fdfsolver_steffenson } }
}
}
pub use ffi::gsl_function_fdf as RootFunctionFdf;
pub struct RootFdfSolver {
s: *mut ffi::gsl_root_fdfsolver,
}
impl RootFdfSolver {
pub fn new(t: &RootFdfSolverType) -> Option<RootFdfSolver> {
let tmp = unsafe { ffi::gsl_root_fdfsolver_alloc(ffi::FFI::unwrap_shared(t)) };
if tmp.is_null() {
None
} else {
Some(RootFdfSolver { s: tmp })
}
}
pub fn set(&mut self, f: &mut RootFunctionFdf, root: f64) -> ::Value {
::Value::from(unsafe {
ffi::gsl_root_fdfsolver_set(self.s, f as *mut RootFunctionFdf, root)
})
}
pub fn iterate(&mut self) -> ::Value {
::Value::from(unsafe { ffi::gsl_root_fdfsolver_iterate(self.s) })
}
pub fn name(&self) -> String {
unsafe {
let tmp = ffi::gsl_root_fdfsolver_name(self.s);
String::from_utf8_lossy(::std::ffi::CStr::from_ptr(tmp).to_bytes()).to_string()
}
}
pub fn root(&self) -> f64 {
unsafe { ffi::gsl_root_fdfsolver_root(self.s) }
}
}
impl Drop for RootFdfSolver {
fn drop(&mut self) {
if !self.s.is_null() {
unsafe {
ffi::gsl_root_fdfsolver_free(self.s);
}
self.s = ::std::ptr::null_mut();
}
}
}