Questions tagged [floating-point]

For challenges which are specific to numbers represented in floating-point format.

Filter by
Sorted by
Tagged with
14 votes
19 answers
3k views

Vanilla Natural Logarithm Challenge

There is a challenge for multiplying two numbers so I guess this counts too Given as input a positive real number n compute its natural logarithm. Your answer ...
mousetail's user avatar
  • 11.8k
11 votes
4 answers
797 views

Implement Perceptron

There was a previous perceptron question but it was closed. Also it required a lot of extra stuff that's not normally part of the perception algorithm like I know it. This question will be much ...
mousetail's user avatar
  • 11.8k
19 votes
21 answers
5k views

Convert an integer to IEEE 754 float

The task is simple: given a 32 bit integer, convert it to its floating point value as defined by the IEEE 754 (32-bit) standard. To put it another way, interpret the integer as the bit-pattern of an ...
zoomlogo's user avatar
  • 1,645
8 votes
2 answers
271 views

Implement Level-Index Addition

Level-index is a system of representing numbers which has been proposed as an alternative to floating-point formats. It claims to virtually eliminate overflow (and underflow, in its symmetric form) ...
att's user avatar
  • 19.8k
15 votes
20 answers
1k views

Cartesian - polar conversion couple

We don't have a challenge for conversion between Cartesian and polar coordinates, so ... The challenge Write two programs (or functions) in the same language: one that converts from polar to ...
Luis Mendo's user avatar
  • 104k
10 votes
9 answers
475 views

Durable Durations

Introduction Time is a really simple concept. Seconds pass, one after the other, all the same. But humans love making it hard. This Stackoverflow question has gathered many answers and even though ...
Nuvanda's user avatar
  • 209
21 votes
14 answers
3k views

Bitwise XOR of floats

This is different from Floating Point XOR, and more in the spirit of a comment by R.. GitHub STOP HELPING ICE on that challenge, but I thought of this idea independently. Generalized XOR The bitwise ...
Ovinus Real's user avatar
10 votes
13 answers
1k views

Smallest numbers whose square has even number of digits

...
AZTECCO's user avatar
  • 10.7k
8 votes
6 answers
599 views

KotH - Floating Point Prisoners Dilemma

Background So, nowadays the popular Prisoner's Dilemma variant is the Prisoner's Trilemma, where there are three options. I can easily see that being increased, so I figured Why settle for three ...
4D4850's user avatar
  • 189
5 votes
21 answers
994 views

Best Rolling Ao5

In speedcubing, an Ao5 (Average of 5) is computed for a set of five times by removing the fastest and slowest times, and then computing the mean of the remaining three times. A "rolling ao5" ...
qwr's user avatar
  • 11.5k
25 votes
8 answers
2k views

Implement Ash's float division

Ash has a bit of an interesting float division algorithm. It's designed to never return NaN, and things like signed zero and infinity need to be handled. How it ...
Rydwolf Programs's user avatar
24 votes
37 answers
2k views

Display the exponent from a binary floating point number as a decimal value

Had my software final exams recently, one of the last questions had me thinking for a while after the exam had finished. Background IEEE754 numbers are according to the below layout The exponent is ...
DarkAndromeda31's user avatar
12 votes
8 answers
1k views

Scientific notation in Base-16

Input a scientific notation number (base 10), output scientific notation in base 16 (as defined below). Details In scientific notation, all non-zero numbers are written in the form $$ m \times 10^n $$ ...
tsh's user avatar
  • 34k
20 votes
13 answers
2k views

Convert Planck unit to SI metric

Objective Given a dimension of an SI unit, convert the Lorentz-Heaviside version of a Planck unit \$1\$ into SI metric. What is a Planck unit? Planck units are a set of units of measurement. It ...
Dannyu NDos's user avatar
  • 5,497
33 votes
31 answers
6k views

How far should I sum?

The harmonic series is the "infinite sum" of all the fractions of the form \$\frac1n\$ for \$n\$ positive integer. I.e. the harmonic series is $$\frac11 + \frac12 + \frac13 + \frac14 + \...
RGS's user avatar
  • 14k
-7 votes
5 answers
361 views

Approximating the amount of prime numbers below `x`

Background We define the prime-counting function, \$\pi(x)\$, as the number of prime numbers less than or equal to \$x\$. You can read about it here. For example, \$\pi(2) = 1\$ and \$\pi(6) = 3\$. ...
RGS's user avatar
  • 14k
22 votes
22 answers
8k views

Floating Point XOR

Your task is pretty simple. Given two floats, bitwise xor the binary representation of them, and output that as a float. For example, ...
virchau13's user avatar
  • 499
4 votes
9 answers
401 views

Floating over the integers

As you may know, the typical binary floating point numbers in a computer language are quite different than the typical integer numbers in a computer language. Floating point numbers can represent a ...
don bright's user avatar
  • 1,305
7 votes
12 answers
867 views

Decimal Digit Truncating

Input: A decimal Output: The input truncated How to truncate them? The integer part of the input will remain the same. The decimal part of the input will be truncated based on the lowest digit in ...
Kevin Cruijssen's user avatar
1 vote
3 answers
871 views

Finding Factorials with Gamma [duplicate]

Introduction We know that the factorial notation is valid for all natural numbers. However, Euler had extended it for all positive real numbers, as well as for complex numbers by defining a function, ...
Manish Kundu's user avatar
  • 5,260
-4 votes
8 answers
304 views

Selling electricity

Jack is a little businessman. He found out a way to earn money by buying electricity on days when it's cheap and selling it when it's much more expensive. He stores the electricity in a battery he ...
McLinux's user avatar
  • 325
12 votes
35 answers
2k views

Output with the same number of digits of pi as the length of the code

Your challenge is to print x digits of pi where x is your code length. Examples: ...
MD XF's user avatar
  • 13.8k
32 votes
24 answers
3k views

Float 754 to Hamming

You will be given as input an integer k in the range from -4503599627370496 (−252) to ...
Luis Mendo's user avatar
  • 104k
4 votes
1 answer
276 views

Find the Closest Double Palindrome

Given a double-precision float, find the closest double-precision float whose binary representation is a palindrome. Input A floating point number x. You may use ...
AJMansfield's user avatar
  • 2,888
-7 votes
6 answers
330 views

Floor implementation

Target: Write a floor() function from scratch. Manipulating like converting float to string, and cutting all after dot are allowed. All languages are allowed. ...
user avatar
15 votes
13 answers
2k views

Decimal Time of Day Conversion

Introduction Time is confusing. Sixty seconds to a minute, sixty minutes to an hour, twenty-four hours to a day (and not to mention that pesky am/pm!). There's no room for such silliness nowadays, so ...
Mwr247's user avatar
  • 3,574
9 votes
3 answers
454 views

Format a floating point number exactly as decimal

Any binary floating point can be formatted exactly in decimal. The resulting string might be somewhat long, but it is possible. In my article on floating point I cover the importance of precision, and ...
edA-qa mort-ora-y's user avatar
6 votes
3 answers
1k views

Compute the shortest decimal representation of a IEEE 754 double-precision binary floating-point number

Format The format is a 64 bit value x representing a IEEE-754 double-precision binary floating-point number (a.k.a "a double"). x is assumed to represent a real number (not a NaN or Infinity). Goal ...
Arthur B's user avatar
  • 310
14 votes
6 answers
608 views

False Positives on an Integer Lattice

Leaderboard ...
Martin Ender's user avatar
12 votes
1 answer
804 views

Implement an IEEE 754 64-bit binary floating point number through integer manipulation

(I've tagged the question "C" for the time being, but if you're aware of another language that supports unions, you can also use that.) Your task is to build the four standard mathematical operators <...
Joe Z.'s user avatar
  • 34.7k
8 votes
11 answers
3k views

Fast inverse square root

Inspired by http://meta.codegolf.stackexchange.com/questions/547/write-a-code-golf-problem-in-which-script-languages-are-at-a-major-disadvantage question on meta, I've decided to make a question which ...
Kamila Borowska's user avatar
10 votes
26 answers
3k views

Machine Epsilon

Machine epsilon is an important floating point number to know when doing numerical calculations. One way to understand it is when this relation ...
leonardo's user avatar
  • 341
8 votes
2 answers
709 views

GolfScript - The missing function

The GolfScript language has one serious lack, no float or fixed point handling. Remedy this by creating a function F for converting an integer number, given as a string, to a string representing 1 / ...
aaaaaaaaaaaa's user avatar
  • 4,395