logb()和ilogb()有什么区别?

时间:2019-04-26 09:33:39

标签: c++ c

如果我理解正确,import tensorflow as tf # Assumes Xval is sorted def interpolate1D(Xval, Fval, inp): # Make sure input values are tensors Xval = tf.convert_to_tensor(Xval) Fval = tf.convert_to_tensor(Fval) inp = tf.convert_to_tensor(inp) # Find the interpolation indices c = tf.count_nonzero(tf.expand_dims(inp, axis=-1) >= Xval, axis=-1) idx0 = tf.maximum(c - 1, 0) idx1 = tf.minimum(c, tf.size(Xval, out_type=c.dtype) - 1) # Get interpolation X and Y values x0 = tf.gather(Xval, idx0) x1 = tf.gather(Xval, idx1) f0 = tf.gather(Fval, idx0) f1 = tf.gather(Fval, idx1) # Compute interpolation coefficient x_diff = x1 - x0 alpha = (inp - x0) / tf.where(x_diff > 0, x_diff, tf.ones_like(x_diff)) alpha = tf.clip_by_value(alpha, 0, 1) # Compute interpolation return f0 * (1 - alpha) + f1 * alpha properties = { 'xval': [200.0, 400.0, 600.0, 800.0, 1100.0], 'fval': [100.0, 121.6, 136.2, 155.3, 171.0] } with tf.Graph().as_default(), tf.Session() as sess: tensor = tf.placeholder("float") interpolate = interpolate1D(properties['xval'], properties['fval'], tensor) print(sess.run(interpolate, feed_dict={tensor: [40.0, 530.0, 800.0, 1200.0]})) # [100. 131.09 155.3 171. ] 将同时处理 $this->validate($request, [ 'title' =>'required', 'featured'=>'required|mimes:jpeg,pdf,docx,png:5000', 'file'=>'required|mimes:jpeg,pdf,docx,png:5000', 'content'=>'required', 'category_id'=>'required', ]); $featured= $request->featured; $featured_new_name=time().$featured->getClientOriginalName(); $featured->move('uploads/posts', $featured_new_name); $file=$request->file; $file_name=time().$file->getClientOriginalName(); $file->move('uploads/posts', $file_name); $post = Post::create([ 'title'=>$request->title, 'content'=>$request->content, 'featured'=>'uploads/posts/'. $featured_new_name, 'file'=>'uploads/posts'. $file_name, 'category_id'=>$request->category_id, 'slug'=>str_slug($request->title) ]); Session::flash('success', 'New Blog has been Published on Website for Particular Menu'); return redirect()->back(); } ilogb()参数(并返回0NaN),而{{1} }引发域错误。据我所知,没有理由使用FP_ILOGB0。这两个函数之间是否还有其他区别,是否有任何理由使用FP_ILOGBNAN而不是logb()

2 个答案:

答案 0 :(得分:2)

除了返回类型,如果函数的参数为​​零,无穷大或NaN,则返回值,函数之间有no difference in the return value

对于ilogb

  

如果arg不为零,无限或NaN,则返回的值完全等于static_cast<int>(std::logb(arg))

但是,使用功能与POSIX标准略有不同。

对于 ilogb

  

POSIX要求如果arg为零,无穷大,NaN,或者正确的结果超出int的范围,则发生域错误。

     

POSIX还要求在符合XSI的系统上,正确结果大于INT_MAX时返回的值为INT_MAX,而正确结果小于{{1}时返回的值}是INT_MIN

对于logb

  

POSIX要求如果arg为INT_MIN,则会发生极点错误。

答案 1 :(得分:0)

来自the POSIX standard for ilogb

  

成功完成后,这些函数应将x的指数部分作为有符号整数值返回。它们等效于调用相应的logb()函数,并将返回值强制转换为类型int

相关问题