From 8ad35622f6aafce9187b3c9e3a847b0b78db0d23 Mon Sep 17 00:00:00 2001 From: Christoph Holtermann Date: Tue, 22 Mar 2022 11:28:32 +0100 Subject: [PATCH] lean on C Makro for sigfigs --- bindings/python/example_scripts/GncNumeric.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bindings/python/example_scripts/GncNumeric.py b/bindings/python/example_scripts/GncNumeric.py index 50e188009c..32700b856a 100644 --- a/bindings/python/example_scripts/GncNumeric.py +++ b/bindings/python/example_scripts/GncNumeric.py @@ -53,10 +53,16 @@ print("Compare GncNumeric from string (2) to GncNumeric from int (3)") print(g2, "==", g3, ":", g2 == g3) print() -# Create from float with specified precision -print("Create from float with specified precision") -for n in range(0,20): - print(GncNumeric(n4, GNC_DENOM_AUTO, GNC_HOW_DENOM_SIGFIG | n * 0x100)) +def GNC_HOW_DENOM_SIGFIGS(n): + """Leaned on the C Macro""" + return GNC_HOW_DENOM_SIGFIG | (n << 8 & GNC_NUMERIC_SIGFIGS_MASK) + +GNC_NUMERIC_SIGFIGS_MASK = 0x0000ff00 + +# Create from float with specified significant figures +print(f"Create from float (Example 4, ={n4}) with specified significant figures") +for sigfigs in range(0,20): + print(sigfigs, GncNumeric(n4, GNC_DENOM_AUTO, GNC_HOW_DENOM_SIGFIGS(sigfigs))) print() # Convert GncNumeric from float to remove errors