Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float & Integer unary negation #3863

Closed
vicuna opened this issue Nov 14, 2005 · 2 comments
Closed

Float & Integer unary negation #3863

vicuna opened this issue Nov 14, 2005 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Nov 14, 2005

Original bug ID: 3863
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Frederic Loulergue
Version: all
OS: Linux
Submission from: 193.49.83.4 (193.49.83.4)

Ocaml Manual indicates that :
~-3 could be written -3
~-3 could be written -.3

but -3. is accepted and evaluated to -:float = -. 3.

If it is not a bug it is an ugly feature

@vicuna
Copy link
Author

vicuna commented Nov 16, 2005

Comment author: administrator

Hello,

Full_Name: Frederic Loulergue

Ocaml Manual indicates that :
~-3 could be written -3
~-3 could be written -.3

No. ~- and ~-. are prefix operators. When - and -. are used as prefix
operators
(instead of infix), the parser converts them to ~- and ~-. respectively.

This means that (- x) is the same as (- x),
and (-. x) is the same as (
-. x).

but -3. is accepted and evaluated to -:float = -. 3.

Constants are another matter. -3. is a floating-point constant, not
the application of unary negation to a number. You see the difference when
using it in a pattern:

fun (-3.) -> true;; <- this works
fun (-~. 3.) -> true;; <- this doesn't work

If it is not a bug it is an ugly feature

The ugliness is in mathematics: using the same identifier for two different
functions: subtraction and negation. We are only propagating this ugliness
because of the principle of least astonishment.

-- Damien

@vicuna vicuna closed this as completed Nov 16, 2005
@vicuna
Copy link
Author

vicuna commented Nov 16, 2005

Comment author: administrator

Constants are another matter. -3. is a floating-point constant, not
the application of unary negation to a number.

Euh oui ok j'ai honte.
Désolé du dérangement et merci pour la réponse.

Très cordialement,

FL

@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant