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

exponential format not used if value is zero #48

Open
alusiani opened this issue Jan 2, 2021 · 4 comments
Open

exponential format not used if value is zero #48

alusiani opened this issue Jan 2, 2021 · 4 comments

Comments

@alusiani
Copy link

alusiani commented Jan 2, 2021

When the value is zero and the uncertainty a very small or very large number, then the exponential format is not used, but it ought to be in my opinion. This is an example

> library(errors)
> x=0
> errors(x)=1.234e10; print(x,digits=4)
0(12340000000)

A possible way to get an exponential formatting could be to get the exponent from the uncertainty when the values is zero, i.e. in print.R changing from

  exponent <- get_exponent(x)

to

  e <- signif(errors(x), digits)
  e_expon = get_exponent(e)
  exponent <- ifelse(as.numeric(x)==0, e_expon+1, get_exponent(x))

Cheers,

@Enchufa2
Copy link
Member

Enchufa2 commented Jan 2, 2021

What do you think that the output should be? And what's special about zero? I mean, why with zero and not with every other number when the uncertainty is bigger than the value?

@alusiani
Copy link
Author

alusiani commented Jan 2, 2021

What do you think that the output should be? And what's special about zero? I mean, why with zero and not with every other number when the uncertainty is bigger than the value?

I think that the output should be 0.000(1234)e-9 rather than 0(12340000000), more similar to what happens when the value is not zero, when the exponential format is used for expressing values/uncertainties >= 1e6.

Regarding values !=0 with uncertainties larger than the values, I see that with the change I suggest here plus the change for getting the decimal point, I get a reasonable formatting:

> x=1.234
> errors(x) = 70.689
> print(x, digits=4)
1.23(70.69)

@Enchufa2
Copy link
Member

Enchufa2 commented Jan 4, 2021

I think that the output should be 0.000(1234)e-9 rather than 0(12340000000), more similar to what happens when the value is not zero, when the exponential format is used for expressing values/uncertainties >= 1e6.

I think you mean 0.000(1234)e10, right? The problem is not whether the value is zero or not, the problem is whether the uncertainty is larger than the value. With non-zero values, you get, e.g.,

> print(set_errors(1e6, 23e10), digits=2)
1(230000)e6

which should be... 0.0001(23000)e11 maybe? So the general case is much more complicated (and I don't see much gain in it, at least in terms of digits required to express the quantities). Also, it could be confusing for the user, because basically we would be inadvertently changing the rules for scientific notation: if uncertainty < value, then it depends on the value; if uncertainty > value, it depends on the uncertainty.

Regarding values !=0 with uncertainties larger than the values, I see that with the change I suggest here plus the change for getting the decimal point, I get a reasonable formatting:

> x=1.234
> errors(x) = 70.689
> print(x, digits=4)
1.23(70.69)

I'm interested here in the formatting with the current default notation, which will continue, as I mentioned in #47, even if we implement your proposal as an optional notation. So please don't merge the issues. Besides, this particular example is just fine now:

> print(set_errors(1.234, 70.689), digits=4)
1.23(7069)

@alusiani
Copy link
Author

alusiani commented Jan 5, 2021

I think that the output should be 0.000(1234)e-9 rather than 0(12340000000), more similar to what happens when the value is not zero, when the exponential format is used for expressing values/uncertainties >= 1e6.

I think you mean 0.000(1234)e10, right? The problem is not whether the value is zero or not, the problem is whether the uncertainty is larger than the value. With non-zero values, you get, e.g.,

I did mean 0.000(1234)e-9, with e10 I would prefer 0.000(1.234)e10, therefore I set the default exponent based on the uncertainty to get a zero on the left of the decimal point.

> print(set_errors(1e6, 23e10), digits=2)
1(230000)e6

which should be... 0.0001(23000)e11 maybe? So the general case is much more complicated (and I don't see much gain in it, at least in terms of digits required to express the quantities). Also, it could be confusing for the user, because basically we would be inadvertently changing the rules for scientific notation: if uncertainty < value, then it depends on the value; if uncertainty > value, it depends on the uncertainty.
...

With the modification I propose:

> print(set_errors(1e6, 23e10), digits=2)
1(230000)e6

In my opinion, a value of zero is not just like a value smaller than its uncertainty, it is rather a value that does not set a scale, and the best scale to minimize the formatted string can be conveniently set by using the scale of the uncertainty.

Let me show an example of what happens with the present code:

> print(set_errors(1e12, 0.1e12), digits=2)
1.00(10)e12
> print(set_errors(0e10, 0.1e12), digits=2)
0(100000000000)

and what happens with the modification I propose

> print(set_errors(1e12, 0.1e12), digits=2)
1.00(10)e12
> print(set_errors(0e10, 0.1e12), digits=2)
0.00(10)e12

Having a value=0 permits formatting both as 0(100000000000) and as 0.00(10)e12 and I prefer the second option.

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

No branches or pull requests

2 participants