Floating-point in Python vs Mathematica [closed] - python-3.x

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Given the limited hardware and its memory we encounter float-point problem. My questions is, how come in Python: 0.1 + 0.1 + 0.1 == 0.3 returns False while Mathematica returns it True?
How did Wolfram guys managed it to work and can Python developers implement their solution?

From the Wolfram documentation at https://reference.wolfram.com/language/ref/Equal.html
Approximate numbers with machine precision or higher are considered equal if they differ in at most their last seven binary digits (roughly their last two decimal digits).
So it's just a different rule for == comparisons.

Related

How to differentiate two forms of percent in a grammar? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 months ago.
Improve this question
I have two forms of "percent" that I need in a grammar:
PERCENT_1
: 'PERCENT'
;
PERCENT_2
: '%'
;
One is the word PERCENT, for example used with something like LIMIT 10 PERCENT and the other is the modulo operator. What might be a good way to differentiate these two things?
One is a keyword, the other an operator. I usually name keyword tokens <name>_SYMBOL and operators <name>_OPERATOR (see the MySQL grammar). Of course this is totally up to you, but should be consistently used throughout your grammar(s).

Seating arrangement problem in a circular table [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
N people sit around a circular table. You have to find the probability that two particular people won't be sitting together.
The input will have the number N and the output should have the probability printed as a float type number rounded off to four decimal places.
Here's the link for the derived formula
You can find the step by step derivation over there
Here's the simple python implementation as per the thread
n = 5
result = (n-3)/(n-1)
print(result)
n= int(input())
import math
print(round(1-math.factorial(n-2)*math.factorial(2)/math.factorial(n-1),4))

The most tiny programming language [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I would like to know what is the most tiny programming language in aspects of commands i.e, which includes the least number of commands.
Is it brainf***k?
Subtract and Branch if Negative (SBN) is a single instruction computer. And it is Turing complete, which means any computer program can be solved using just above instruction.
Such computer is called One Instruction Set Computer. There are several possible single instruction that can be used, some of which are:
Subtract and branch if less than or equal to zero
Subtract and branch if negative
Reverse subtract and skip if borrow
Subtract and branch if non zero

How to avoid scientific notation for large numbers in verilog? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In a case statement case(s), the nvalue of s is increased by the power of 2.
input[127:0] s
output[127:0] y
case(s)
128'b1: y=a1;
128'b2: y=a2;
...
When it goes to 2^64, the number is so big and it will be represented automatically by scientific notation, eg.
128'b1.84467e19: y=a64
This will give me a syntax error, is there a way to avoid this?
I don't want to define it as real, since I want to synthesise this code.
If only one bit of s is set (one-hot), you might be able to use "Constant expression in case statement" (see ยง12.5.2 of the free IEEE Std 1800-2012):
case (1'b1)
s[0] : y=a1;
s[1] : y=a2;
s[127]: y=a64;
endcase

Are all modern currencies based on decimals? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Are all/most modern currencies (mainly used in international business) based on the decimal system.
for example there are 100 pence in a pound, 100 cent in a euro and 100 cent in a dollar.
Is this the same for all currencies major business currencies? (I think it is, im just double checking)
I'd say this is a pretty safe assumption. According to Wikipedia:
Today only two countries in the world use non-decimal currencies. These are Mauritania (1 ouguiya = 5 khoums) and Madagascar (1 ariary = 5 iraimbilanja).

Resources