Writing square root in cplusplus

Pages: 12
Aug 18, 2021 at 11:42am
Square root is available as the function sqrt() declared in <cmath>.
Aug 18, 2021 at 1:00pm
Aug 18, 2021 at 1:21pm
Oh dear! Another one.

https://stackoverflow.com/questions/35295032/writing-square-root-in-cplusplus

Somebody else can get rid of him.
Aug 18, 2021 at 1:31pm
There. Now it looks like a PSA or something.
Aug 18, 2021 at 3:10pm
looks like a PSA

"Hey, kids, don't copy 'n' paste from another website just so you can be a spammer."

That what you lookin' for, helios?
Aug 18, 2021 at 3:15pm
Thanks for the tip!
Aug 18, 2021 at 3:39pm
What's a PSA?
Aug 18, 2021 at 3:42pm
Public Service Announcement
Pretty Stupid Answer
Personal Self Advice
...


Aug 18, 2021 at 3:43pm
They're like public information films.
Aug 18, 2021 at 4:03pm
Ah, I see.

1
2
3
4
5
6
#include <iostream>
void PSA(){std::cout << "        ____\n       /  K\n v =  / 2 -\n    \\/    m\n";}
int main()
{
   PSA();
}
Aug 18, 2021 at 6:05pm
What's a PSA?

Take your pick:
https://acronyms.thefreedictionary.com/PSA
Aug 18, 2021 at 6:30pm
Take your pick:
https://acronyms.thefreedictionary.com/PSA


I have to admit that, despite the 258 possible interpretations that list gives for Helios' post, I chuckled a bit at
Pot Smokers of America
Parrot Society of Australia

It may have started with a repost bot, but you learn something new every day.
Aug 18, 2021 at 7:13pm
A continuing topic started by a repost bot sure can be fun, can't it. Edumakashunal too.
Aug 18, 2021 at 11:23pm
since all we have is a title now, I would not mind a language where you had math symbols like sqrt and so on. With unicode, all that stuff is in it and more, though you would need some way to type them more efficiently.
Aug 19, 2021 at 12:29am
So like LaTeX combined with Maxima? While I like its... terseness, I think we can all agree that mathematical notation is not the most reader-friendly language around. I think my favorite abuse of it is in the Ethereum whitepaper, where it specifies the EVM ISA and its semantics. It's like the writer went "just go ahead and try to figure out how to implement it!"
Aug 19, 2021 at 12:34am
Not even that deep, just at an ease of use level, where you didn't need 4-5 letters to do one symbol.
Aug 19, 2021 at 9:49pm
ctrl+shift+u 221A (hit space)

Dang it, I thought I was on to something, but g++ does not accept the √ symbol in this form:
error: extended character √ is not valid in an identifier

I was trying to #define √ sqrt but hit this roadbloack. I'm trying to find an option to force g++ to accept it but nothing so far.

I've heard of programmable keyboards (though I've never used one), so I was curious if the symbol could be implemented on one of those.

Maybe there's a compiler on github that takes in unicode source files.
Last edited on Aug 19, 2021 at 9:58pm
Aug 19, 2021 at 9:54pm
The preprocessor still works at the identifier level. You can't #define arbitrary strings of tokens as macros.
Aug 19, 2021 at 10:13pm
Good tip, with that I was able to do it with pi π, but that just looks like nonsense, why would π(30) return sqrt(30)? Too bad √ is not in the allowed list. Short of making a recommendation to the C/C++ standards committee, it looks like it's not happening any time soon.

I guess you could pick another greek symbol to represent sqrt(), but there's still the effort of getting a programmable keyboard.
Last edited on Aug 19, 2021 at 10:14pm
Aug 19, 2021 at 10:28pm
You could #define that_nonnegative_number_whose_square_is sqrt .
Pages: 12