<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">In the
      SCI/modules/string/sci_gateway/cpp/sci_string.cpp source file,<br>
      is defined<br>
      types::Function::ReturnValue <b>intString</b>(T* pInt,
      types::typed_list &out)<br>
      {<br>
          int iDims = pInt->getDims();<br>
          int* piDimsArray = pInt->getDimsArray();<br>
          types::String *pstOutput = new types::String(iDims,
      piDimsArray);<br>
          int iSize = pInt->getSize();<br>
          for (int i = 0 ; i < iSize ; i++)<br>
          {<br>
              std::wostringstream ostr;<br>
              DoubleComplexMatrix2String(&ostr, <b>(double)</b>pInt->get(i),
      0);<br>
              pstOutput->set(i, ostr.str().c_str());<br>
          }<br>
      where integers are converted into decimal before being sent to
      DoubleComplexMatrix2String()<br>
      to be formated as a decimal.<br>
      There are at least 3 different algos to do the same thing (i guess
      not only for integers)...:<br>
       - the disp() one (that is OK for integers)<br>
       - the string() one (NOK)<br>
       - the printf() one (NOK)<br>
       - and may be other ones...<br>
      <br>
      <br>
      Le 29/08/2016 02:09, Tim Wescott a écrit :<br>
    </div>
    <blockquote cite="mid:1472429361.3023.62.camel@Servo" type="cite">
      <pre wrap="">A kludge would be to make it into two integers.  This works for positive
integers, but verifying (or modifying) the algorithm to signed numbers
is left as an exercise to the reader:

A = (some 64-bit constant)
A_1 = A / 1000000000;
A_0 = A - A_1 * 1000000000;

if (A_1 == 0)
  mprintf("A = %d\n", A);
else
  mprintf("A = %d%09d\n", A_1, A_0);
end // if

Woo hoo!  Eight lines and an if statement where you wanted something
embedded in mprintf.  What could be better?

On Mon, 2016-08-29 at 00:05 +0200, Samuel Gougeon wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">Hello all,

I am wondering how it is possible to print (in a file, in a string)
new 64 bit integers,
at full accuracy. Their relative accuracy is better than for decimal
numbers
(1/2^63 instead of %eps=1/2^52).

In Scilab 5, digits lower than 1/%eps -- that are somewhat randomly
set --
can be displayed but are not relevant:
-->format(24)
-->%pi
 %pi  =
    3.141592653589793115998

-->(%pi-3.141592653589793)==0
 ans  =
  T  

In Scilab 6, digits beyond %eps are displayed as 0. This is great:
--> format(24)
--> %pi
 %pi  = 
   3.141592653589793100000

However, this change is applied to all numbers, even to integers.
The issue is that Scilab 6 also brings super-integers :) int64 /
uint64
having 64-bit mantissae, instead of 53-bit mantissae for decimal
numbers.
Hence, int64 have a relative accuracy better than %eps.
Unfortunately the related digits can't be printed.
Only the default display in console works.
Examples:
i = int64(2)^62 + 1
printf("%d  %i  %ld  %li \n", i, i ,i, i)
format(22)
string(i)
// I found this undocumented trick with printf format, but there is
the same truncature:
printf("%20.0f\n", i)

// Results:
--> i = int64(2)^62 + 1
 i  = 
  4611686018427387905        // The right value!

--> printf("%d  %i  %ld  %li \n", i, i ,i, i)
-2147483648  -2147483648  -2147483648  -2147483648    // Oups. %lld
does nor work

--> format(22)
--> string(i)
 ans  =
 4611686018427387900        // bad trailing zeros

--> // I found this undocumented trick with printf format, but there
is the same truncature:
--> printf("%20.0f\n", i)
 4611686018427387900        // Same issue (final 5 missing)


I started looking for a solution with write() and its fortran
formating,
but it looks no more ready for int64 integers.

Would you know any solution?

Thanks
Samuel

_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
      </blockquote>
      <pre wrap="">
</pre>
    </blockquote>
    <br>
  </body>
</html>