5 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 # See https://llvm.org/LICENSE.txt for license information.
7 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 import matplotlib
.pyplot
as plt
15 # build/bin/ulp -e .0001 log 0.5 2.0 2345678 | math/tools/plot.py
18 return float.fromhex(s
)
25 # Has to match the format used in ulp.c
26 r
= re
.compile(r
'[^ (]+\(([^ )]*)\) got ([^ ]+) want ([^ ]+) [^ ]+ ulp err ([^ ]+)')
38 elif line
.startswith('PASS') or line
.startswith('FAIL'):
39 # Print the summary line
43 def plot(xs
, gs
, ys
, es
):
45 print('not enough samples')
49 fig
, (ax0
,ax1
) = plt
.subplots(nrows
=2)
50 es
= np
.abs(es
) # ignore the sign
52 ax0
.text(a
+(b
-a
)*0.7, emax
*0.8, '%s\n%g'%(emax
.hex(),emax
))
55 ax1
.plot(xs
,ys
,'r.',label
='want')
56 ax1
.plot(xs
,gs
,'b.',label
='got')
61 xs
, gs
, ys
, es
= parse(sys
.stdin
)