Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to set dicimal digits for printing floating number #357

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

k-okada
Copy link
Member

@k-okada k-okada commented Dec 30, 2018

dicimal digits of floating number. to recover original number from character representation, choose 17 for 64 bit machine and 9 for 32bit machine

See
https://en.m.wikipedia.org/wiki/IEEE_754#Character_representation
( https://teratail.com/questions/22355 for Japanese)

1.eusgl$ (print 1234.56789)
1234.57
1234.57
2.eusgl$ (setq lisp::*print-precision* 17)
17
3.eusgl$ (print 1234.56789) 
1234.5678899999994
1234.5678899999994

NOTE:

(print (v- #f(1234.56789) (float-vector 1234.56789)))

returns #f(0.00211) when compiled, and #f(0.0) for source because compiled files becomes

init_ftab();
��������local[0]= fqv[0];
��������local[1]= makeflt(1.2345678899999993518577e+03);
��������ctx->vsp=local+2;
��������w=(pointer)MKFLTVEC(ctx,1,local+1); /*float-vector*/
��������local[1]= w;
��������ctx->vsp=local+2;
��������w=(pointer)VMINUS(ctx,2,local+0); /*v-*/
��������local[0]= w;
��������ctx->vsp=local+1;
��������w=(pointer)PRINT(ctx,1,local+0); /*print*/

And

define QUOTE_STRINGS_SIZE 2
static char *quote_strings[QUOTE_STRINGS_SIZE]={
    "#f(1234.57)",
    "exit",
  };

FYI: @YoheiKakiuchi

@k-okada k-okada changed the title Print precision Enable to set dicimal digits for printing floating number Dec 30, 2018
k-okada added a commit to k-okada/jskeus that referenced this pull request Dec 30, 2018
k-okada added a commit to k-okada/jskeus that referenced this pull request Dec 30, 2018
k-okada added a commit to k-okada/jskeus that referenced this pull request Dec 30, 2018
k-okada added a commit to k-okada/jskeus that referenced this pull request Jan 4, 2019
@Affonso-Gui
Copy link
Member

Is it correct to take this as a measure to print float numbers in full precision when writing to files? e.g. compiling, dump-object etc.

If it must be set to 17 in 64bit and 9 in 32bit can't we use some sort of #+/#- syntax to adapt to the running system architecture?

Having a *print-precision* variable may seem to be an alternative to (format t "~1,3f" 1234.5678) forms, which is probably not what we want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants