From dc2e9d01d7b17d4d3a30cc03ec07b815cc2c7bf3 Mon Sep 17 00:00:00 2001
From: "serg@serg.mylan" <>
Date: Mon, 6 Dec 2004 15:08:26 +0100
Subject: [PATCH] int decimal_is_zero(decimal *from);

---
 include/decimal.h |  8 +-------
 strings/decimal.c | 10 ++++++++++
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/decimal.h b/include/decimal.h
index 5b5b8c0b46..fddae1f54a 100644
--- a/include/decimal.h
+++ b/include/decimal.h
@@ -51,13 +51,7 @@ int decimal_mul(decimal *from1, decimal *from2, decimal *to);
 int decimal_div(decimal *from1, decimal *from2, decimal *to, int scale_incr);
 int decimal_mod(decimal *from1, decimal *from2, decimal *to);
 int decimal_round(decimal *from, decimal *to, int new_scale, decimal_round_mode mode);
-
-/*
-  the following works only on special "zero" decimal, not on any
-  decimal that happen to evaluate to zero
-*/
-
-#define decimal_is_zero(dec) ((dec)->intg1==1 && (dec)->frac1==0 && (dec)->buf[0]==0)
+int decimal_is_zero(decimal *from);
 
 /* set a decimal to zero */
 
diff --git a/strings/decimal.c b/strings/decimal.c
index 6b2982d8d8..2dcc2c88ce 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -1240,6 +1240,16 @@ int decimal_cmp(decimal *from1, decimal *from2)
   return from1->sign > from2->sign ? -1 : 1;
 }
 
+int decimal_is_zero(decimal *from)
+{
+  dec1 *buf1=from->buf,
+       *end=buf1+ROUND_UP(from->intg)+ROUND_UP(from->frac);
+  while (buf1 < end)
+    if (*buf1++)
+      return 0;
+  return 1;
+}
+
 /*
   multiply two decimals
 
-- 
2.30.9