'Does my Postgres instance support IEEE 754 double precision floats?
According to the docs Postgres double precision type implements IEEE 754 : “The data types real and double precision are inexact, variable-precision numeric types. On all currently supported platforms, these types are implementations of IEEE Standard 754 for Binary Floating-Point Arithmetic (single and double precision, respectively), to the extent that the underlying processor, operating system, and compiler support it.”
My question is then how do I check that "the underlying processor, operating system, and compiler support it"? Is it somewhat common that this is not the case?
Clarification
I want to check if my specific Postgres instance is compliant. Is there some kind of test(s) that I can do running SQL queries in order to verify or disprove that?
Solution 1:[1]
It is very common for today's computers to use IEEE 754 floating point numbers. So much so that even in the wide range of platforms supported by PostgreSQL, all do. The only way to check is to look at the specification and documentation of the hardware or software in question.
PostgreSQL uses whatever the compiler and machine provide for the C data type double. It does not implement floating point arithmetic itself.
Solution 2:[2]
One way to do this on the front-end (without using a database) is to add all the objects, in this case the dogs data, inside of an array and then use filter() to select the searched object. Finally return the data to the event listener and create the HTML output.
const input = document.getElementById('input'),
btn = document.getElementById('btn'),
container = document.getElementById('container');
var dogs = [
new Dog("spot", "10kg"),
new Dog("snoop", "20kg"),
new Dog("snoopy", "100kg")
]
function Dog(name, weight) {
this.name = name
this.weight = weight
}
function find(name) {
let info = dogs.filter(dog => dog.name === name)
return info[0]
}
btn.addEventListener("click", function(){
let dogInfo = find(input.value),
html = `name: ${dogInfo.name} <br> weight: ${dogInfo.weight}`
container.innerHTML = html
})
<label>Dog name: </label>
<input id="input" type="text" value="spot">
<button id="btn">Show info</button>
<br><br>
<div id="container"></div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Laurenz Albe |
| Solution 2 |
