Thread: Double to Array Implementation - Truncation or Rounding

  1. #1
    Banned
    Join Date
    Jul 2022
    Posts
    112

    Double to Array Implementation - Truncation or Rounding

    I will be writing dtoa, the original version includes rounding or truncation, or both ?

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,127
    Quote Originally Posted by kodax View Post
    I will be writing dtoa, the original version includes rounding or truncation, or both ?
    dtoa() is not a standard function, and it is usually described as "Double to ASCII".

    Look at one implementation of the function which should answer your question, and show how one implementation has been written. There may be others on Github and other sites. Google for more results.

  3. #3
    Banned
    Join Date
    Jul 2022
    Posts
    112
    Printf only rounds, printf("|%.f| |%.1f| |%.2f| |%.5f| |%.12f", 0.000099, 0.000099, 0.000099, 0.000099, 0.000099);
    output: |0| |0.0| |0.00| |0.00010| |0.000099000000

    This is what I meant by truncation, "-12.520008900" is truncated to "-12.52", because of 3 consecutive '0'.

  4. #4
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    rstanley recommendation remains true: "Look at one implementtion of the function which should answer your question..."

  5. #5
    Banned
    Join Date
    Jul 2022
    Posts
    112
    The whole thing is cluttered and cryptic, the only one who will understand that is the author.

    Code:
    //dtoa.c
    word0(rvp) = ((b->x[1] & ~0x800000) >> 16) | ((e + 129 + 55) << 7) | (b->x[1] << 16);
    I just want to know if there is truncation.

    Adding truncation and rounding is possible, but is there a need for truncation ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. avoiding numeric rounding/truncation errors
    By philgrek in forum C Programming
    Replies: 0
    Last Post: 04-13-2011, 09:41 PM
  2. Rounding off a double
    By C-Dummy in forum C Programming
    Replies: 3
    Last Post: 06-23-2008, 11:45 AM
  3. rounding up a double.
    By akidamo in forum C Programming
    Replies: 6
    Last Post: 04-08-2006, 10:35 AM
  4. Warning message truncation 'double' to 'float'
    By Tojam in forum C Programming
    Replies: 4
    Last Post: 05-01-2002, 02:21 AM
  5. Rounding & DOUBLE type
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 04-17-2002, 05:29 PM

Tags for this Thread