On an NXP Semiconductors MCU such as the LPC55S69, a UART baud rate is derived from a system clock and an integer divider. Given a system clock, an oversampling factor, and a list of target baud rates, write a function that computes the best divider for each target baud and returns the resulting actual baud rate and percentage error.
Use the formula:
actual_baud = system_clock / (oversample * divider)
For each target baud rate, choose the positive integer divider that minimizes absolute percentage error. If two dividers produce the same error, return the smaller divider.
system_clock: integer clock frequency in Hzoversample: integer oversampling factortargets: list of integer target baud rates[target_baud, divider, actual_baud, error_percent]actual_baud and error_percent should be rounded to 2 decimal places.Example 1
Input: system_clock = 12000000, oversample = 16, targets = [9600]
Output: [[9600, 78, 9615.38, 0.16]]
Explanation: Divider 78 gives 12000000 / (16 * 78) = 9615.38, which is the closest achievable baud.
Example 2
Input: system_clock = 48000000, oversample = 16, targets = [115200, 1000000]
Output: [[115200, 26, 115384.62, 0.16], [1000000, 3, 1000000.0, 0.0]]
Explanation: Divider 26 is best for 115200, and divider 3 gives an exact 1,000,000 baud.
1 <= len(targets) <= 10^41 <= system_clock <= 10^91 <= oversample <= 2561 <= targets[i] <= 10^7