Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Infinity Sign

Tags:

c++

codeblocks

Hello I was just wondering how I can display the infinity (∞) in C++? I am using CodeBlocks. I read couple of Q&A's on this topic but I'm a newbie at this stuff, especially with Hex coding and stuff. What do I have to include and what do I type out exactly. If someone can write the code and explain it, that'd be great! Thanks!

like image 587
Maty Avatar asked Apr 03 '15 17:04

Maty


People also ask

What is infinity in C?

INFINITY is a macro constant defined in the <math. h> library, and programmers use it to perform mathematical comparisons in C. #include <math.h>

Is ∞ a number?

Infinity is not a number. Instead, it's a kind of number. You need infinite numbers to talk about and compare amounts that are unending, but some unending amounts—some infinities—are literally bigger than others.

How do you type an infinite sign?

How to type infinity symbol on keyboard. Hold the ALT key and type 236 on the num-lock keypad.


2 Answers

The symbol is not part of the ASCII code. However, in the code page 437 (most of the time the default in Windows Command Prompt with English locales/US regional settings) it is represented as the character #236. So in principle

std::cout << static_cast<unsigned char>(236);

should display it, but the result depends on the current locale/encoding. On my Mac (OS X) it is not displayed properly.

The best way to go about it is to use the UNICODE set of characters (which standardized a large amount of characters/symbols). In this case,

std::cout << "\u221E"; 

should do the job, as the UNICODE character #221 represents inf.

However, to be able to display UNICODE, your output device should support UTF encoding. On my Mac, the Terminal uses UTF, however Windows Command Prompt still uses the old ASCII encoding CodePage 437 (thanks to @chris for pointing this out). According to this answer, you can change to UNICODE by typing

chcp 65001

in a Command Prompt.

like image 55
vsoftco Avatar answered Sep 29 '22 08:09

vsoftco


You can show it through its UNICODE

∞ has the value: \u221E

You can show any character from the Character Map by its unicode.

like image 33
A.D. Avatar answered Sep 29 '22 06:09

A.D.