Re: ICU4C API proposal - int64 support for NumberFormat

Deborah Goldsmith <[email protected]>
Newsgroups gmane.comp.lib.icu.general
Message-ID <[email protected]>
What about the C APIs in unum.h? Those need extension as well, along 
the lines of:

unum_formatInt64(...
unum_parseInt64(...

Deborah Goldsmith
Manager, Fonts / Unicode liaison
Apple Computer, Inc.
[email protected]

On Oct 31, 2003, at 3:13 PM, Doug Felt wrote:

> API change - add int64_t support to NumberFormat and associated 
> classes.
> See Jitterbug #813
> Please respond by Nov 7th.
>
> Note, there are two kinds of potential errors in user code that are 
> revealed by
> these changes (because they occurred in our tests)
>
> 1) Assuming that if a Formattable is a number and not a long, it is a 
> double.
> 2) Assuming that if a number is too large to fit in a long, then it 
> must be a
> double.
>
> The first occurred in a test that was converting all the formattables 
> to
> doubles.  It was testing the type of the formattable, and if it was 
> not kLong
> or kDouble, was returning an error.  Now there is a new type, kInt64, 
> which
> invalidated this old assumption.  It's a general problem when 
> extending a fixed
> range of types, people sometimes write code that doesn't rely on 
> positive
> identification of the type and instead relies on elimination, and this 
> fails.
>
> The second occurred in a test that was taking the maximum long value, 
> as a
> double and multiplying it by 1000.  This resulted in a double value 
> that
> represented an integer value.  The test tried to round trip this to 
> text and
> back, and just assumed (without checking) that the formattable must 
> contain a
> double, since it was 'too large' for the int representation.  This is 
> no longer
> true as an int64_t could hold the (integral) value of the original 
> double.
>
> Affected files:
>
> -tests-
> tsnmfmt.h
> numrgts.cpp
> numfmtst.cpp/h
>
> -i18n-
> fmtable.cpp/h
> numfmt.cpp/h
> digitlst.cpp/h (to be moved to i18n from common.  internal API)
> decimfmt.cpp/h
> choicfmt.cpp/h
>
> Affected APIs:
>
> -- Formattable--
> (Internally, stores int64_t instead of int32_t for its integral data.  
> All
> int32_t APIs remain and are augmented with similar int64_t APIs.)
>
>     /**
>      * Creates a Formattable object with an int64 number
>      * @param ll the int64 number.
>      * @draft ICU 2.8
>      */
>     Formattable(int64_t ll);
>
>     /**
>      * The list of possible data types of this Formattable object.
>      * @draft ICU 2.4
>      */
>     enum Type {
> 		/** @draft ICU 2.4 */
>         kDate,      // Date
> 		/** @draft ICU 2.4 */
>         kDouble,    // double
> 		/** @draft ICU 2.4 */
>         kLong,      // long
> 		/** @draft ICU 2.4 */
>         kString,    // UnicodeString
> 		/** @draft ICU 2.4 */
>         kArray,     // Formattable[]
> 		/** @draft ICU 2.8 */
>  		kInt64      // int64
>    };
>
>     /**
>      * Gets the int64 value of this object.
>      * @return    the int64 value of this object.
>      * @draft ICU 2.8
>      */
>     int64_t          getInt64(void) const;
>
>    /**
>      * Sets the int64 value of this object.
>      * @param ll    the new int64 value to be set.
>      * @draft ICU 2.8
>      */
>     void            setInt64(int64_t ll);
>
>
> -- NumberFormat --
> (APIs that took int32_t are overloaded to take int64_t.  Note, rather 
> than
> introducing
> a new pure virtual method overload, I gave the overload an 
> implementation so
> that
> existing user subclasses will still compile (we have such a class in 
> our
> tests).
>
>     /**
>      * Format an int64 number. These methods call the NumberFormat
>      * pure virtual format() methods with the default FieldPosition.
>      *
>      * @param number    The value to be formatted.
>      * @param appendTo  Output parameter to receive result.
>      *                  Result is appended to existing contents.
>      * @return          Reference to 'appendTo' parameter.
>      * @draft ICU 2.8
>      */
>     UnicodeString& format(  int64_t number,
>                             UnicodeString& appendTo) const;
>
>     /**
>      * Format an int64 number. (Not abstract to retain compatibility
>   * with earlier releases, however subclasses should override this
>   * method as it just delegates to format(int32_t number...);
>      *
>      * @param number    The value to be formatted.
>      * @param appendTo  Output parameter to receive result.
>      *                  Result is appended to existing contents.
>      * @param pos       On input: an alignment field, if desired.
>      *                  On output: the offsets of the alignment field.
>      * @return          Reference to 'appendTo' parameter.
>      * @draft ICU 2.8
>     */
>     virtual UnicodeString& format(int64_t number,
>                                   UnicodeString& appendTo,
>                                   FieldPosition& pos) const;
>
> -- DecimalFormat --
> (concrete implementation of NumberFormat)
>
>     /**
>      * Format an int64 number using base-10 representation.
>      *
>      * @param number    The value to be formatted.
>      * @param appendTo  Output parameter to receive result.
>      *                  Result is appended to existing contents.
>      * @param pos       On input: an alignment field, if desired.
>      *                  On output: the offsets of the alignment field.
>      * @return          Reference to 'appendTo' parameter.
>      * @draft ICU 2.8
>      */
>     virtual UnicodeString& format(int64_t number,
>                                   UnicodeString& appendTo,
>                                   FieldPosition& pos) const;
>
>     /**
>      * Redeclared NumberFormat method.
>      * Format an int64 number. These methods call the NumberFormat
>      * pure virtual format() methods with the default FieldPosition.
>      *
>      * @param number    The value to be formatted.
>      * @param appendTo  Output parameter to receive result.
>      *                  Result is appended to existing contents.
>      * @return          Reference to 'appendTo' parameter.
>      * @draft ICU 2.8
>      */
>     UnicodeString& format(int64_t number,
>                           UnicodeString& appendTo) const;
>
> -- ChoiceFormat --
> (This has to change since new overrides were added in NumberFormat, a 
> base
> class.
> Since ChoiceFormat's implementation is based on doubles, this has no
> interesting
> implementation.)
>
>     /**
>      * Format an int_64t number using this object's choices.
>      *
>      * @param number    The value to be formatted.
>      * @param appendTo  Output parameter to receive result.
>      *                  Result is appended to existing contents.
>      * @param pos       On input: an alignment field, if desired.
>      *                  On output: the offsets of the alignment field.
>      * @return          Reference to 'appendTo' parameter.
>      * @draft ICU 2.8
>      */
>     virtual UnicodeString& format(int64_t number,
>                                   UnicodeString& appendTo,
>                                   FieldPosition& pos) const;
>
>
> __________________________________
> Do you Yahoo!?
> Exclusive Video Premiere - Britney Spears
> http://launch.yahoo.com/promos/britneyspears/
> _______________________________________________
> icu mailing list
> [email protected]
> http://oss.software.ibm.com/developerworks/oss/mailman/listinfo/icu
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.