contributed by < willy-liu >
Q1: 不使用 FPU 指令進行浮點數開平方根
Assume x is a single precision floating point number and always >= 1. Calculate square root (casting to int for easing complexity) without FPU, as precise as FPU operations.
int my_sqrtf(float x){}
首先注意到為了讓題目可以在十分鐘內回答出來,老師簡化了回傳值,並且限定輸入>=1,而我當下太在意小數點的精確度,而回答了 IEEE 754 的浮點數規格,然後打算用 LUT 的方式確保小數點,但這題若只要回傳"整數",我們就需要確認精確度的問題。
二分搜尋法
先考慮計算無條件捨去的情況