utf8 mathematical operators in c++ ?

82 views
Skip to first unread message

god...@gmail.com

unread,
Feb 22, 2017, 12:42:02 PM2/22/17
to ISO C++ Standard - Discussion
== Problem ==
I would like to implement a geometric algebra library in c++ similar to this one http://versor.mat.ucsb.edu/ .

In this context, I have a dot product (middle dot), a wedge product (wedge), a geometric product (usual multiplication), and a commutator product (cross), which are all multiplications in the mathematical sense. However, there is not enough operators available in c++ which match approximately those mathematical symbols. What I have is operator* for the usual multiplication, operator^ for the wedge product, and that's it.

For instance, the versor library that I have mentioned uses the operator% for the commutator, and the operator<= for the dot product. I find it quite clumsy that I need to hack some operators to give them a completely non intuitive meaning.

== Proposal ==
What I would like is to be able to use the proper mathematical symbols, but they are multi-byte characters and not c++ operators. I understand that having multi-byte characters in c++ files would lead to some issues, but I believe it is manageable and could be very helpful in some cases. It would also allow some people to write code in their native language.

A possible solution would be to allow multi-byte characters in a c++ file, only if the file starts with a line with a new special formatting which specifies in which encoding the file is written (maybe something like "[[encoding:utf8]]" or "//encoding - utf8").

Then, we could either extend the set of existing operators, or provide a way to define custom operators with special characters.


Brittany Friedman

unread,
Feb 22, 2017, 12:58:21 PM2/22/17
to std-dis...@isocpp.org
The C++ standard places no requirements on how translation units are encoded. It is the compiler's job to decide how to open and read files. UTF-8 is one of many valid ways to convert a file into the supported character set of C++. Your compiler is also allowed to use UCS-2, UTF-16, UTF-32, .jpg files with optical character recognition, or speech-to-text conversion over a .wav file. What matters to the standard is the characters, not how the compiler got those characters. If your compiler doesn't support UTF-8 then you should ask them to support it.

If you want to *extend the character set* and add *new operators* to the language that is an entirely different problem that has nothing to do with encoding. Proposals to add new operators to the language should be sent to the std-proposals mailing list, not std-discussion. 

god...@gmail.com

unread,
Feb 22, 2017, 1:25:29 PM2/22/17
to ISO C++ Standard - Discussion
Well yes, there are two distinct problems indeed, *extend the character set* and add *new operators*.

For the moment, encoding does not matter since the current character set is restricted to single-byte characters. But you are right that it is not the main issue since maybe just a compiler flag would do, using the locale as default.

Nicol Bolas

unread,
Feb 22, 2017, 1:51:58 PM2/22/17
to ISO C++ Standard - Discussion, god...@gmail.com
On Wednesday, February 22, 2017 at 1:25:29 PM UTC-5, god...@gmail.com wrote:
Well yes, there are two distinct problems indeed, *extend the character set* and add *new operators*.

For the moment, encoding does not matter since the current character set is restricted to single-byte characters. But you are right that it is not the main issue since maybe just a compiler flag would do, using the locale as default.

Regardless of how you describe it, the problem is best discussed here.

god...@gmail.com

unread,
Feb 22, 2017, 2:07:22 PM2/22/17
to ISO C++ Standard - Discussion, god...@gmail.com
Ok, I will look there, and create a new topic there if I don't find anything related.

Let's consider this closed here, thank you.
Reply all
Reply to author
Forward
0 new messages