Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.sys.mac.programmation > #2103
| From | "M.V." <mv@gmail.com.invalid> |
|---|---|
| Newsgroups | fr.comp.sys.mac.programmation |
| Subject | Re: Y a comme un défaut |
| Date | 2021-12-04 14:49 +0000 |
| Organization | M.V. & Co |
| Message-ID | <sofv6h$psa$1@dont-email.me> (permalink) |
| References | <1pjmz6k.1v0nod6mfq0rkN%josephb@nowhere.invalid> <j0vto8FsgsuU1@mid.individual.net> <1pjnmh9.11fmmgjvnnxyuN%josephb@nowhere.invalid> <j1168nF58rjU1@mid.individual.net> <1pjo2wu.1hc52gb1l7s1a3N%josephb@nowhere.invalid> |
[Supersedes: <sofuv0$lof$1@dont-email.me>]
Le 4 décembre 2021 à 15 h 25, Joseph-B a tenu les propos suivants :
> Pour reprendre l'exemple de MV,
> (2.001 -2) avec une calculette à moins d'un euro retournera 0,001
> Ouais, mais c'est moche et trivial tandis que
> (2.001 -2) dans AppleScript retournera 9.9999999999989E-4
En même temps on n'est pas loin de la vérité mathématique car, si tu te
rappelles tes cours de math du siècle dernier :
1 = 0,99999999999999999999999999999999… (ad libitum) ! ;-)
Ceci dit, je partage ton courroux (coucou) surtout quand je vois le
script que j'ai dû pondre pour obtenir un résultat correct (jusqu'à
preuve du contraire) pour éviter des résultats à la mords-moi le nœud.
J'en suis là :
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
set diviseur to 25.4
set serie to {0.254, 2.54, 25.4001, 254, 2540}
set restes to {}
set text item delimiters to " - "
set commentaire to "Restes de la division par " & (diviseur as text) & " de" & linefeed & (serie as string)
set exp0 to exp_value(diviseur)
log "exp0 : " & exp0
repeat with value in serie
set exp1 to exp_value(value)
log "exp1 : " & exp1
-- pour transformer 25.4 et 25.4001 par exemple en 254000 et 254001
if exp1 ≥ exp0 then
set exp to exp1
else
set exp to exp0
end if
set new_value to (value * (10 ^ exp)) as integer
set new_diviseur to (diviseur * (10 ^ exp)) as integer
set reste to (new_value mod new_diviseur) / (10 ^ exp)
if reste = (reste as integer) then set reste to reste as integer
copy reste to the end of restes
end repeat
set text item delimiters to " - "
display alert (restes's every item as text) message commentaire
-- combien de chiffres dans la partie décimale
on exp_value(nombre)
set nombre_str to nombre as string
log "nombre_str : " & nombre_str
set text item delimiters to ","
try
set exp to count characters of second text item of nombre_str
on error
set exp to 0
end try
return exp
end exp_value
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
--
Michel VAUQUOIS - <http://michelvauquois.fr>
Back to fr.comp.sys.mac.programmation | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Y a comme un défaut josephb@nowhere.invalid (Joseph-B) - 2021-12-04 00:54 +0100
Re: Y a comme un défaut pehache <pehache.7@gmail.com> - 2021-12-04 02:14 +0100
Re: Y a comme un défaut josephb@nowhere.invalid (Joseph-B) - 2021-12-04 10:14 +0100
Re: Y a comme un défaut Olivier Miakinen <om+news@miakinen.net> - 2021-12-04 12:48 +0100
Re: Y a comme un défaut josephb@nowhere.invalid (Joseph-B) - 2021-12-04 13:16 +0100
Re: Y a comme un défaut Olivier Miakinen <om+news@miakinen.net> - 2021-12-04 13:23 +0100
Calculette IEEE754 (was: Y a comme un défaut) Olivier Miakinen <om+news@miakinen.net> - 2021-12-04 14:39 +0100
Re: Y a comme un défaut pehache <pehache.7@gmail.com> - 2021-12-04 13:46 +0100
Re: Y a comme un défaut josephb@nowhere.invalid (Joseph-B) - 2021-12-04 15:25 +0100
Re: Y a comme un défaut "M.V." <mv@gmail.com.invalid> - 2021-12-04 14:49 +0000
Re: Y a comme un défaut josephb@nowhere.invalid (Joseph-B) - 2021-12-04 19:21 +0100
Re: Y a comme un défaut "M.V." <mv@gmail.com.invalid> - 2021-12-04 18:58 +0000
Re: Y a comme un défaut Benoit <benoit@com.invalid> - 2021-12-04 16:35 +0000
Re: Y a comme un défaut pehache <pehache.7@gmail.com> - 2021-12-04 17:39 +0100
Re: Y a comme un défaut josephb@nowhere.invalid (Joseph-B) - 2021-12-04 19:21 +0100
Re: Y a comme un défaut pehache <pehache.7@gmail.com> - 2021-12-04 20:28 +0100
Re: Y a comme un défaut JPP <jpp@findelmundo.invalid> - 2021-12-05 03:24 -0300
Re: Y a comme un défaut Julien Salort <listes@salort.eu> - 2021-12-05 09:51 +0100
Re: Y a comme un défaut Fleuger <g4fleurot@free.fr.invalid> - 2021-12-04 08:27 +0000
Re: Y a comme un défaut Fleuger <g4fleurot@free.fr.invalid> - 2021-12-04 09:00 +0000
Re: Y a comme un défaut "M.V." <mv@gmail.com.invalid> - 2021-12-04 09:25 +0000
Re: Y a comme un défaut Fleuger <g4fleurot@free.fr.invalid> - 2021-12-04 13:01 +0000
Re: Y a comme un défaut "M.V." <mv@gmail.com.invalid> - 2021-12-04 14:27 +0000
Re: Y a comme un défaut josephb@nowhere.invalid (Joseph-B) - 2021-12-04 10:14 +0100
Re: Y a comme un défaut "M.V." <mv@gmail.com.invalid> - 2021-12-04 09:30 +0000
Re: Y a comme un défaut josephb@nowhere.invalid (Joseph-B) - 2021-12-04 12:57 +0100
Re: Y a comme un défaut pehache <pehache.7@gmail.com> - 2021-12-04 14:16 +0100
Re: Y a comme un défaut "M.V." <mv@gmail.com.invalid> - 2021-12-04 14:18 +0000
Re: Y a comme un défaut "M.V." <mv@gmail.com.invalid> - 2021-12-04 10:30 +0000
Re: Y a comme un défaut "M.V." <mv@gmail.com.invalid> - 2021-12-04 08:45 +0000
Re: Y a comme un défaut JPP <jpp@findelmundo.invalid> - 2021-12-04 14:16 -0300
Re: Y a comme un défaut "Néo, l'Élu" <neo-de-matrix@meta-science.fr> - 2022-02-07 10:56 +0000
csiph-web