calc
calc copied to clipboard
Alternative representations of some results.
Some calculations like 1/3 that results in ~0.33333333333333333333 or -1/3 ~-0.33333333333333333333
I believe it would be better to add a space, so that results shows like ~ 0.33333333333333333333 ~ -0.33333333333333333333
or in alternative a space followed by ellipsis at the end (that is a space and 3 dots, not the utf-8 for the ellipsis), like the followed: 0.33333333333333333333 ... -0.33333333333333333333 ...
it would be nice users can configure the representation of such numbers, either as a ~ or ... or both, however the space after ~ should really exist, since in a fast glace, in my terminal I took ~0.333 by -0.333.
Also....
In the site example:
config("mode", "fraction"), (17/19)^23
19967568900859523802559065713/257829627945307727248226067259
base(16), (19/17)^29
0x9201e65bdbb801eaf403f657efcf863/0x5cd2e2a01291ffd73bee6aa7dcf7d1
There should be spaces on both sides of '/', I very much doubt everyone can see that result is a fraction, I didn't saw it at first...
so results should be: 19967568900859523802559065713 / 257829627945307727248226067259
0x9201e65bdbb801eaf403f657efcf863 / 0x5cd2e2a01291ffd73bee6aa7dcf7d1
I would do it some of the changes myself, however I have no ideia where to change this in the source code.
Thanks
This is a very interesting proposal! We will look into the details, @ljramalho
It may be a bit before this happens. Stay tuned.
As an update, we are thinking the there may be a non-default mode that would replace leafing ~ with trailing ....
As far as the spaces go, a version 2.15 could print spaces, as you suggest by default and allow someone to consider some sort of no space if they wanted older behavior.
We need to shop this around to people with hardware driven by calc, and other long time users, to get their feedback, so it may be a month or more before we test some code, @ljramalho.
We are going to try in address this useful enhancement in calc version 2.14.2.0 or 2.14.2.1, @ljramalho, stay tuned!
See the top of the master branch or at least commit 0d99ba54d81a8cfe073c9b7047eae634a920bef3 for an implementation of config("tilde_space", 1), which is now default, @ljramalho
Added config("tilde_space", boolean). The "tilde_space" controls whether or not a space (' ') is printed after leading tilde ('~'). By default, config("tilde_space") is true, which is a change from past behavior. For example, now:
; 1/3
~ 0.33333333333333333333
With config("tilde_space", 0):
; 1/3
~0.33333333333333333333
Hello @ljramalho,
There is a difficulty in implementing printing a space around the fraction mode.
Consider:
a=0;
x = strprintf("%r", 1/3);
print x;
strscanf(x, "%r", a);
print a;
Currently this wound produce:
; a=0;
; x = strprintf("%r", 1/3);
; print x;
1/3
; strscanf(x, "%r", a);
1
; print a;
~0.33333333333333333333
If the space fraction mode were implemented, it would produce:
; a=0;
; x = strprintf("%r", 1/3);
; print x;
1 / 3
; strscanf(x, "%r", a);
1
; print a;
1
That is, the %r scan would not pick up the fraction because it is no longer "1/3". While one could code the %r scan to look for "1 / 3", that would impact a scan of other tokens. Consider:
a=0;
b=0;
x = strprintf("%r", 1/3);
strscanf("1/3foo", "%r%s", a, b),;
print a, b;
Instead of printing, as it does now:
~0.33333333333333333333 foo
it would, with spaces around a fraction, produce:
1 /
I.e., existing calc code would break.
So in order to not break existing calc code, the printing of fractions via things like printf() and strprintf() would have to be different than printing of values that were fractions on the command line. But that would break functions line scan() and strscanf() unless they were also changed. However that in turn would break existing calc scripts.
UPDATE 0
We have to think about this some more. We might be able to get away with spaces around fractions if it was not on by default. This would still mess up the scan() and strscanf() of %r but perhaps this could be documented as a "feature". I.e., note that setting some for of config("fraction_space", 1) breaks use of %r and %c.
UPDATE 1
With commit 17702a47994c93813276f194da00aca8889be876, calc can print fractions with spaces around then, but not by default.
There may be a problem if config("tilde_space") defaults to 1 (enabled).
Consider:
x=strprintf("%c", sqrt(7 + 5i,1e-100));
print x;
With config("tilde_space",0) we have:
"~2.79305614578749801863+~0.89507688693280053094i"
However with config("tilde_space",1) we have:
"~ 2.79305614578749801863+~ 0.89507688693280053094i"
We are gong to set the default to config("tilde_space",0).
So if you want to print space after the approximation tilde, put this into your ~/.calcrc:
config("tilde_space",1),;
So for now, as of commit 7c6723db88bd0adf81f4e94e89567b3fa06751ed, the default is to NOT print a space after the approximation tilde. sigh
UPDATE 0
The printing of complex values should also be addressed.
Printing values such as:
"~2.79305614578749801863+~0.89507688693280053094i"
or with config("tilde_space",1):
"~ 2.79305614578749801863+~ 0.89507688693280053094i"
might be better as:
"~ 2.79305614578749801863 + ~ 0.89507688693280053094i"
Via some new config("complex_space") mode.
With commit 17702a47994c93813276f194da00aca8889be876, calc can print fractions with spaces around then, but not by default.
Added config("fraction_space", boolean). The "fraction_space" controls whether or not a space (' ') is printed before and after fractions. By default, config("fraction_space") is false.
For example, with the default, config("fraction_space", 0):
; base(1/3),
; 1/7
1/7
With config("fraction_space", 1):
; base(1/3),
; 1/7
1 / 7
NOTE: Use of config("fraction_space", 1) can break printing and scanning of fractional values via "%r".
NOTE: Use of config("fraction_space", 1) can break printing and scanning of complex values via "%c".
Added config("fraction_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test config("tilde_space").
UPDATE 0
The issue if space around complex values, as noted in comment 1336266998 has not yet been implemented.
UPDATE 1
For now, because these modes are not default, you can put this into your ~/.calcrc file:
config("tilde_space",1),;
config("fraction_space",1),;
With commit f4f19f21dc0ad272ae905ebc856c3713702282d4 calc can print complex values with spaces around the + or - (between the real and imaginary values).
Added config("fraction_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test config("tilde_space").
Added config("complex_space", boolean). The "complex_space" controls whether or not a space (' ') is printed before and after the + or - in complex values.
By default, config("complex_space") is false.
For example, with the default, config("complex_space", 0):
; asin(2)
1.57079632679489661923-1.31695789692481670863i
With config("complex_space", 1):
; asin(2)
1.57079632679489661923 - 1.31695789692481670863i
NOTE: Use of config("complex_space", 1) can break printing and scanning of fractional values via "%r".
NOTE: Use of config("complex_space", 1) can break printing and scanning of complex values via "%c".
Added config("complex_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test config("complex_space").
UPDATE 0
For now, because these modes are not default, you can put this into your ~/.calcrc file:
config("tilde_space",1),;
config("fraction_space",1),;
config("complex_space",1),;
With commit f4f19f21dc0ad272ae905ebc856c3713702282d4 @ljramalho we will declare this enhancement complete.