mp-units icon indicating copy to clipboard operation
mp-units copied to clipboard

Unicode output for fractional exponents

Open mpusz opened this issue 5 years ago • 12 comments

Provide nice Unicode symbols for fractional exponents wherever possible.

using namespace units;
using namespace units::si::literals;

std::cout << sqrt(1m) << "\n";

mpusz avatar Feb 14 '20 20:02 mpusz

which unicode code points? Couldn't obviously find superscript fractions. Or did you mean "radical" symbols like an actual square root. That would be most unusual? or did you just mean m^½ currently it prints: m^(1/2)

oschonrock avatar Feb 22 '20 21:02 oschonrock

I think that "m½" is self-explanatory and we might not need additional "^" sign but we can decide otherwise. Here is the info how to create any ratio: https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts.

mpusz avatar Feb 23 '20 10:02 mpusz

yes. I know about "composing fractions using sub/superscripts", but those are not "superscripts overall" and therefore only questionably suitable for representing an exponent?

In fact I think it's logical that fractional superscripts don't exist as a font glyph. The single digit superscripts are difficult enough to read at normal font sizes, so fractional superscripts would likely be unreadable below 20pt? Really to display this sort of thing properly we need a "1.5 x line height" (at least) layout object, and we clearly can't do that without outputting postscript or latex.

So you are suggesting, we abandon the idea of the these actually being exponents/superscripts?

and just write (effectively) "m * 1/2" ?

oschonrock avatar Feb 23 '20 10:02 oschonrock

So you are suggesting, we abandon the idea of the these actually being exponents/superscripts? and just write (effectively) "m * 1/2"?

No. If we are about to stay with ASCII I think that the current spelling "m^(1/2)" is better. It is that in one of the libraries I analyzed I saw they use unicodes for fractional exponents too and the resulting dimensions were easier to read (in my opinion).

mpusz avatar Feb 23 '20 10:02 mpusz

That's a misunderstanding. I agree that the best ASCII is the status quo.

What I was trying to point out is that

to my eyes (and this is subjective) looks more like

m * (1/2)

than like

m^(1/2)

actually m½ doesn't look like anything very sensible to my eyes.

In my opinion writing non-trivial mathematical expressions nicely is not really possible "on a single line of text". That's why there are specialised languages for that. And a basic convention for how to use ASCII, which is not too pretty, but unambiguous.

oschonrock avatar Feb 23 '20 11:02 oschonrock

My understanding is that fractional exponents will usually appear in intermediate results and will be printed mostly for debugging purposes. I don't see much need in perfecting their looks.

i-ky avatar Feb 23 '20 12:02 i-ky

There are ony a few physical quantities that really use them. I was provided one of them some time ago but I lost it and do not remember the name of the quantity.

mpusz avatar Feb 23 '20 16:02 mpusz

I did some googling and it led me to this discussion (funny enough, about another physical units library) and there are a couple of examples:

  1. fracture toughness measured in Pa · m1/2
  2. amplitude spectral density involving Hz−1/2

i-ky avatar Feb 23 '20 17:02 i-ky

@i-ky what you have there looks much better to my eyes!

superscript, but just simple '/' fraction...you can still see it's an exponent

unless someone objects I'll just implement that ... but not go overboard since it seems this is pretty niche

oschonrock avatar Feb 23 '20 18:02 oschonrock

@oschonrock what I'm using there is not plain Unicode, I've cheated using <sup>...</sup>. And although you can get superscript digits, there is no way to represent superscript solidus with Unicode.

i-ky avatar Feb 23 '20 19:02 i-ky

@i-ky Damn, but somehow I smelled that.

Oh well, this can remain on low priority table then, given we are struggling to come up with a use case outside of "amplitude spectral density".

oschonrock avatar Feb 23 '20 19:02 oschonrock

Well, we can always cheat: https://stackoverflow.com/a/49325148 ;-)

mpusz avatar Feb 24 '20 13:02 mpusz