• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
      • Std/lists
      • Omaps
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
        • Pretty-printing
        • Printtree
        • Base64
        • Charset-p
        • Strtok!
        • Cases
        • Concatenation
        • Character-kinds
        • Html-encoding
        • Substrings
        • Strtok
        • Equivalences
        • Url-encoding
        • Lines
        • Explode-implode-equalities
        • Ordering
        • Numbers
          • Decimal
            • Parse-nat-from-string
            • Parse-nat-from-charlist
            • Nat-to-dec-chars
            • Dec-digit-char-p
            • Dec-digit-chars-value
            • Dec-digit-char-listp
            • Take-leading-dec-digit-chars
            • Dec-digit-char-value
            • Dec-digit-char-list*p
            • Nat-to-dec-string-width
            • Nat-to-dec-string
            • Dec-digit-string-p
            • Strval
            • Skip-leading-digits
            • Nat-to-dec-string-size
            • Int-to-dec-string-width
              • Int-to-dec-string
              • Nonzero-dec-digit-char-p
              • Nat-to-dec-string-list
              • Int-to-dec-string-list
              • Revappend-nat-to-dec-chars
            • Hex
            • Octal
            • Binary
          • Pad-trim
          • Coercion
          • Std/strings/digit-to-char
          • Substitution
          • Symbols
        • Std/osets
        • Std/io
        • Std/basic
        • Std/system
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Decimal

    Int-to-dec-string-width

    Convert an integer into a string with a fixed number of digits.

    Signature
    (int-to-dec-string-width i width) → str
    Arguments
    i — Guard (integerp i).
    width — Guard (posp width).
    Returns
    str — Type (stringp str).

    Definitions and Theorems

    Function: int-to-dec-string-width

    (defun int-to-dec-string-width (i width)
     (declare (xargs :guard (and (integerp i) (posp width))))
     (let ((acl2::__function__ 'int-to-dec-string-width))
      (declare (ignorable acl2::__function__))
      (b*
       ((i (mbe :logic (ifix i) :exec i))
        (width (mbe :logic (if (posp width) width 1)
                    :exec width))
        (chars
           (if (< i 0)
               (b* ((chars (nat-to-dec-chars (- i))))
                 (cons #\-
                       (cond ((<= width (len chars))
                              (nthcdr (- (len chars) width) chars))
                             (t (append (make-list (- width (len chars))
                                                   :initial-element #\0)
                                        chars)))))
             (b* ((chars (nat-to-dec-chars i)))
               (cond ((<= width (len chars))
                      (nthcdr (- (len chars) width) chars))
                     (t (append (make-list (- width (len chars))
                                           :initial-element #\0)
                                chars)))))))
       (implode chars))))

    Theorem: stringp-of-int-to-dec-string-width

    (defthm stringp-of-int-to-dec-string-width
      (b* ((str (int-to-dec-string-width i width)))
        (stringp str))
      :rule-classes :type-prescription)

    Theorem: int-to-dec-string-width-nonempty

    (defthm int-to-dec-string-width-nonempty
      (not (equal (int-to-dec-string-width i width)
                  "")))