• FRACTION() seems broken in gfortran 12.2

    From Woozy Song@suzyw0ng@outlook.com to comp.lang.fortran on Thu Aug 14 11:21:00 2025
    From Newsgroup: comp.lang.fortran

    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Thomas Koenig@tkoenig@netcologne.de to comp.lang.fortran on Thu Aug 14 16:47:19 2025
    From Newsgroup: comp.lang.fortran

    Woozy Song <suzyw0ng@outlook.com> schrieb:
    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375

    Do you have a self-contained example (something that can be compiled)?
    --
    This USENET posting was made without artificial intelligence,
    artificial impertinence, artificial arrogance, artificial stupidity,
    artificial flavorings or artificial colorants.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lynn McGuire@lynnmcguire5@gmail.com to comp.lang.fortran on Thu Aug 14 15:44:58 2025
    From Newsgroup: comp.lang.fortran

    On 8/13/2025 10:21 PM, Woozy Song wrote:
    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375

    Have you tried upgrading to a newer version of gfrotran ?

    Gfortran is now at version 15.2 ???
    https://gcc.gnu.org/

    Version 12 of Gfortran was no longer supported at version 12.5 ???
    https://gcc.gnu.org/gcc-12/

    Lynn

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Louis Krupp@lkrupp@invalid.pssw.com.invalid to comp.lang.fortran on Fri Aug 15 02:09:23 2025
    From Newsgroup: comp.lang.fortran

    On 8/13/2025 9:21 PM, Woozy Song wrote:
    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375

    I tried it with gfortran version 15, just for fun, and I got the same
    result. A search for the fraction intrinsic turned up this:

    https://stackoverflow.com/questions/27686204/wrong-output-of-the-intrinsic-function-fraction-in-fortran

    Louis
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Thomas Koenig@tkoenig@netcologne.de to comp.lang.fortran on Fri Aug 15 16:16:42 2025
    From Newsgroup: comp.lang.fortran

    Louis Krupp <lkrupp@invalid.pssw.com.invalid> schrieb:
    On 8/13/2025 9:21 PM, Woozy Song wrote:
    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375

    I tried it with gfortran version 15, just for fun, and I got the same result.

    For

    print *,FRACTION(3.75)
    print *,FRACTION(2.5)
    end program

    I get the same result for gfortran 12, 13, 14, 15 and current trunk:

    0.937500000
    0.625000000

    So, please provide a failing test case that actually compiles.
    --
    This USENET posting was made without artificial intelligence,
    artificial impertinence, artificial arrogance, artificial stupidity,
    artificial flavorings or artificial colorants.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.fortran on Fri Aug 15 22:24:52 2025
    From Newsgroup: comp.lang.fortran

    On Thu, 14 Aug 2025 11:21:00 +0800, Woozy Song wrote:

    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375

    Broken as designed, according to the spec.

    Why on Earth does FRACTION have this meaning?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Steven G. Kargl@sgk@REMOVEtroutmask.apl.washington.edu to comp.lang.fortran on Sun Aug 17 00:02:35 2025
    From Newsgroup: comp.lang.fortran

    On Fri, 15 Aug 2025 22:24:52 +0000, Lawrence D’Oliveiro wrote:

    On Thu, 14 Aug 2025 11:21:00 +0800, Woozy Song wrote:

    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375

    Broken as designed, according to the spec.

    Why on Earth does FRACTION have this meaning?

    To what spec are you referring?

    gfortran is giving the correct answer (although
    I suspect OP has a transcription problem with
    the second example).
    --
    steve
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Gary Scott@garylscott@sbcglobal.net to comp.lang.fortran on Sat Aug 16 20:40:13 2025
    From Newsgroup: comp.lang.fortran

    On 8/16/2025 7:02 PM, Steven G. Kargl wrote:
    On Fri, 15 Aug 2025 22:24:52 +0000, Lawrence D’Oliveiro wrote:

    On Thu, 14 Aug 2025 11:21:00 +0800, Woozy Song wrote:

    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375

    Broken as designed, according to the spec.

    Why on Earth does FRACTION have this meaning?

    To what spec are you referring?

    gfortran is giving the correct answer (although
    I suspect OP has a transcription problem with
    the second example).


    I think most casual, non-math, non-floating point experts would expect this:

    "The fractional part of a real number is the decimal portion of the
    number, excluding the integer part. It represents the difference between
    the real number and its integer part. This is often denoted by curly
    braces {x} or frac(x).
    In more detail:
    Real Number Representation:
    Every real number can be expressed as the sum of an integer and a
    fractional part. For example, 3.14 can be written as 3 + 0.14, where 3
    is the integer part and 0.14 is the fractional part.
    Fractional Part Function:
    The fractional part function, denoted by {x}, is defined as the
    difference between the real number x and its integer part.
    Formula:
    {x} = x - ⌊x⌋, where ⌊x⌋ is the floor function (the greatest integer less than or equal to x).
    Example:
    If x = 3.14, then {x} = 3.14 - ⌊3.14⌋ = 3.14 - 3 = 0.14.
    Range:
    The fractional part of a number is always between 0 and 1 (inclusive of
    0, exclusive of 1). For integers, the fractional part is 0. "

    So, they would expect fraction(3.0) to be 0, not 0.75.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Steven G. Kargl@sgk@REMOVEtroutmask.apl.washington.edu to comp.lang.fortran on Sun Aug 17 03:18:03 2025
    From Newsgroup: comp.lang.fortran

    On Sat, 16 Aug 2025 20:40:13 -0500, Gary Scott wrote:

    On 8/16/2025 7:02 PM, Steven G. Kargl wrote:
    On Fri, 15 Aug 2025 22:24:52 +0000, Lawrence D’Oliveiro wrote:

    On Thu, 14 Aug 2025 11:21:00 +0800, Woozy Song wrote:

    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375

    Broken as designed, according to the spec.

    Why on Earth does FRACTION have this meaning?

    To what spec are you referring?

    gfortran is giving the correct answer (although
    I suspect OP has a transcription problem with
    the second example).


    I think most casual, non-math, non-floating point experts would expect this:

    For someone programming in the Fortran language, I would expect
    that they would consult some form of documentation to learn why
    their expectation might be wrong. For example, the gfortran
    documentation (which comes with the compiler) contains


    8.119 ‘FRACTION’ -- Fractional part of the model representation ===============================================================

    _Synopsis_:
    ‘Y = FRACTION(X)’

    _Description_:
    ‘FRACTION(X)’ returns the fractional part of the model
    representation of ‘X’.

    _Class_:
    Elemental function

    _Arguments_:
    X The type of the argument shall be a ‘REAL’.

    _Return value_:
    The return value is of the same type and kind as the argument. The
    fractional part of the model representation of ‘X’ is returned; it
    is ‘X * RADIX(X)**(-EXPONENT(X))’.

    _Example_:
    program test_fraction
    real :: x
    x = 178.1387e-4
    print *, fraction(x), x * radix(x)**(-exponent(x))
    end program test_fraction
    --
    steve
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.fortran on Sun Aug 17 07:15:43 2025
    From Newsgroup: comp.lang.fortran

    On Sat, 16 Aug 2025 20:40:13 -0500, Gary Scott wrote:

    I think most casual, non-math, non-floating point experts would expect
    this:

    "The fractional part of a real number is the decimal portion of the
    number, excluding the integer part. It represents the difference between
    the real number and its integer part.

    Sure. Except that computers typically do not represent floating-point
    numbers in decimal, but in binary. This is the significance of the “model representation” phrase in the language spec.

    The way you describe is obviously the most natural interpretation, these
    days. And most other languages do it that way. But not Fortran.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Gary Scott@garylscott@sbcglobal.net to comp.lang.fortran on Sun Aug 17 09:11:52 2025
    From Newsgroup: comp.lang.fortran

    On 8/17/2025 2:15 AM, Lawrence D’Oliveiro wrote:
    On Sat, 16 Aug 2025 20:40:13 -0500, Gary Scott wrote:

    I think most casual, non-math, non-floating point experts would expect
    this:

    "The fractional part of a real number is the decimal portion of the
    number, excluding the integer part. It represents the difference between
    the real number and its integer part.

    Sure. Except that computers typically do not represent floating-point
    numbers in decimal, but in binary. This is the significance of the “model representation” phrase in the language spec.

    The way you describe is obviously the most natural interpretation, these days. And most other languages do it that way. But not Fortran.

    Yes, which is abhorrent.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Steven G. Kargl@sgk@REMOVEtroutmask.apl.washington.edu to comp.lang.fortran on Sun Aug 17 22:30:15 2025
    From Newsgroup: comp.lang.fortran

    On Sun, 17 Aug 2025 07:15:43 +0000, Lawrence D’Oliveiro wrote:

    On Sat, 16 Aug 2025 20:40:13 -0500, Gary Scott wrote:

    I think most casual, non-math, non-floating point experts would expect
    this:

    "The fractional part of a real number is the decimal portion of the
    number, excluding the integer part. It represents the difference between
    the real number and its integer part.

    Sure. Except that computers typically do not represent floating-point numbers in decimal, but in binary. This is the significance of the “model representation” phrase in the language spec.

    The way you describe is obviously the most natural interpretation, these days. And most other languages do it that way. But not Fortran.


    Most modern languages likely expect a user to do
    something like 'x = x - (int)x;' or 'x = x - int(x)'
    or some variation thereof if a user wants the decimal
    fraction.

    Let's see. Hmmm, C23 offer 'y = frexp(x,&n)', which
    returns the fractional part of the floating point
    representation. That would be 'x = y * 2**n' with y
    in [0.5,1) for a binary foating point number. Fortran
    2023 happens to have 'y = fraction(x)' with y in [0.5,1)
    for binary FP and does not have a side effect.

    C23 has 'y = frexpd64(x,&n)' but I doubt that the user
    uses '_Decimal64 x'. Not to mention, that frexpd64()
    returns 'x = y * 10**n' with y in [1/10,1), which is not
    the decimal fractional part that one gets with
    'x = x - (int)x;' Fortran 2023 allows a processor to
    support a base-10 REAL, and because 'fraction()' is a
    generic subprogram 'y = fraction(x)' would return
    y in [1/10,1) for a base-10 REAL x.

    Perhaps, you're referring to C23's modf(x, &y) function.
    But, C23's modf() does something entirely different than
    Fortran 2023 mod() (and modulo()) function. If Fortran
    had something like modf(), it would be a subroutine to
    avoid a function with a side effect.

    Finally, if x is an array, in Fortran one can do
    'x = x - (int)x'. C23 would be
    'for (int i = 0; i < imax; i++) x[i] = x[i] - (int)x[i];'
    One of these is a bit more elegant.
    --
    steve


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Kay Diederichs@kay.diederichs@gmx.net to comp.lang.fortran on Tue Aug 19 12:15:37 2025
    From Newsgroup: comp.lang.fortran

    Am 8/17/25 um 05:18 schrieb Steven G. Kargl:
    On Sat, 16 Aug 2025 20:40:13 -0500, Gary Scott wrote:

    On 8/16/2025 7:02 PM, Steven G. Kargl wrote:
    On Fri, 15 Aug 2025 22:24:52 +0000, Lawrence D’Oliveiro wrote:

    On Thu, 14 Aug 2025 11:21:00 +0800, Woozy Song wrote:

    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375

    Broken as designed, according to the spec.

    Why on Earth does FRACTION have this meaning?

    To what spec are you referring?

    gfortran is giving the correct answer (although
    I suspect OP has a transcription problem with
    the second example).


    I think most casual, non-math, non-floating point experts would expect this:

    For someone programming in the Fortran language, I would expect
    that they would consult some form of documentation to learn why
    their expectation might be wrong. For example, the gfortran
    documentation (which comes with the compiler) contains


    8.119 ‘FRACTION’ -- Fractional part of the model representation ===============================================================

    _Synopsis_:
    ‘Y = FRACTION(X)’

    _Description_:
    ‘FRACTION(X)’ returns the fractional part of the model
    representation of ‘X’.

    _Class_:
    Elemental function

    _Arguments_:
    X The type of the argument shall be a ‘REAL’.

    _Return value_:
    The return value is of the same type and kind as the argument. The
    fractional part of the model representation of ‘X’ is returned; it
    is ‘X * RADIX(X)**(-EXPONENT(X))’.

    _Example_:
    program test_fraction
    real :: x
    x = 178.1387e-4
    print *, fraction(x), x * radix(x)**(-exponent(x))
    end program test_fraction


    Thank you, Steve.

    The following program, adapted from the Example in the documentation you cite:

    program test_fraction
    real :: x
    x = 3.75
    print *, fraction(x), x
    print *, x * radix(x)**(-exponent(x))
    end program test_fraction

    prints:
    0.937500000 3.75000000
    0.00000000

    but I was expecting it to print:
    0.937500000 3.75000000
    0.937500000

    because the documentation says that fraction(x) is the same as x * radix(x)**(-exponent(x)) .

    I suggest that the documentation is wrong, and should say
    ' ... model representation of ‘X’ is returned; it is ‘X * REAL(RADIX(X))**(-EXPONENT(X))’.

    Concerning the OP's finding that FRACTION(2.5) is printed as 0.9375:
    I cannot reproduce that with gfortran 11.5.0 or 13.3.1 or 14.2.1 which all correctly calculate 0.625 .

    So to me this is a documentation bug, and possibly a bug in gfortran 12.2 .

    Hope this helps,
    Kay


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Steven G. Kargl@sgk@REMOVEtroutmask.apl.washington.edu to comp.lang.fortran on Tue Aug 19 15:29:34 2025
    From Newsgroup: comp.lang.fortran

    On Tue, 19 Aug 2025 12:15:37 +0200, Kay Diederichs wrote:

    Am 8/17/25 um 05:18 schrieb Steven G. Kargl:
    On Sat, 16 Aug 2025 20:40:13 -0500, Gary Scott wrote:

    On 8/16/2025 7:02 PM, Steven G. Kargl wrote:
    On Fri, 15 Aug 2025 22:24:52 +0000, Lawrence D’Oliveiro wrote:

    On Thu, 14 Aug 2025 11:21:00 +0800, Woozy Song wrote:

    A program was going wrong, and found
    FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375

    Broken as designed, according to the spec.

    Why on Earth does FRACTION have this meaning?

    To what spec are you referring?

    gfortran is giving the correct answer (although
    I suspect OP has a transcription problem with
    the second example).


    I think most casual, non-math, non-floating point experts would expect this:

    For someone programming in the Fortran language, I would expect
    that they would consult some form of documentation to learn why
    their expectation might be wrong. For example, the gfortran
    documentation (which comes with the compiler) contains


    8.119 ‘FRACTION’ -- Fractional part of the model representation
    ===============================================================

    _Synopsis_:
    ‘Y = FRACTION(X)’

    _Description_:
    ‘FRACTION(X)’ returns the fractional part of the model
    representation of ‘X’.

    _Class_:
    Elemental function

    _Arguments_:
    X The type of the argument shall be a ‘REAL’.

    _Return value_:
    The return value is of the same type and kind as the argument. The
    fractional part of the model representation of ‘X’ is returned; it >> is ‘X * RADIX(X)**(-EXPONENT(X))’.

    _Example_:
    program test_fraction
    real :: x
    x = 178.1387e-4
    print *, fraction(x), x * radix(x)**(-exponent(x))
    end program test_fraction


    Thank you, Steve.

    The following program, adapted from the Example in the documentation you cite:

    program test_fraction
    real :: x
    x = 3.75
    print *, fraction(x), x
    print *, x * radix(x)**(-exponent(x))
    end program test_fraction

    prints:
    0.937500000 3.75000000
    0.00000000

    but I was expecting it to print:
    0.937500000 3.75000000
    0.937500000

    because the documentation says that fraction(x) is the same as x * radix(x)**(-exponent(x)) .

    I suggest that the documentation is wrong, and should say
    ' ... model representation of ‘X’ is returned; it is ‘X * REAL(RADIX(X))**(-EXPONENT(X))’.

    Concerning the OP's finding that FRACTION(2.5) is printed as 0.9375:
    I cannot reproduce that with gfortran 11.5.0 or 13.3.1 or 14.2.1 which all correctly calculate 0.625 .

    So to me this is a documentation bug, and possibly a bug in gfortran 12.2 .

    Looks like you've found a documentation bug. The Fortran standard
    actually has

    Result Value. The result has the value $X \times b^{-e}$,
    where $b$ and $e$ are as defined in 16.4 for the representation
    of X in the extended real model for the kind of X. ...

    where I have marked-up the sentence in LaTeX. IOW, when the gfortran documentation was written, someone transcripted the equation
    $X \times b^{-e}$ into Fortran without realizing RADIX returns an
    integer.
    --
    steve


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Steven G. Kargl@sgk@REMOVEtroutmask.apl.washington.edu to comp.lang.fortran on Tue Aug 19 17:58:06 2025
    From Newsgroup: comp.lang.fortran

    On Tue, 19 Aug 2025 15:29:34 +0000, Steven G. Kargl wrote:

    On Tue, 19 Aug 2025 12:15:37 +0200, Kay Diederichs wrote:

    So to me this is a documentation bug, and possibly a bug in gfortran
    12.2 .

    Looks like you've found a documentation bug. The Fortran standard
    actually has

    Patch submitted

    https://gcc.gnu.org/pipermail/fortran/2025-August/062714.html
    --
    steve
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From pehache@pehache.7@gmail.com to comp.lang.fortran on Mon Sep 8 15:25:28 2025
    From Newsgroup: comp.lang.fortran

    Le 17/08/2025 à 09:15, Lawrence D’Oliveiro a écrit :
    On Sat, 16 Aug 2025 20:40:13 -0500, Gary Scott wrote:

    I think most casual, non-math, non-floating point experts would expect
    this:

    "The fractional part of a real number is the decimal portion of the
    number, excluding the integer part. It represents the difference between
    the real number and its integer part.

    Sure. Except that computers typically do not represent floating-point
    numbers in decimal, but in binary. This is the significance of the “model representation” phrase in the language spec.

    The way you describe is obviously the most natural interpretation, these days. And most other languages do it that way. But not Fortran.


    Can you elaborate on what these "most other languages" are ? I cannot
    find any intrinsic function that corresponds to the "most natural interpretation" in most of the popular languages around (C, C++, Pthon,
    Java, Rust, Matlab...)
    --
    "...sois ouvert aux idées des autres pour peu qu'elles aillent dans le
    même sens que les tiennes.", ST sur fr.bio.medecine
    ST passe le mur du çon : <j3nn2hFmqj7U1@mid.individual.net>
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.fortran on Mon Sep 8 22:16:57 2025
    From Newsgroup: comp.lang.fortran

    On Mon, 8 Sep 2025 15:25:28 +0200, pehache wrote:

    Le 17/08/2025 à 09:15, Lawrence D’Oliveiro a écrit :

    The way you describe is obviously the most natural interpretation,
    these days. And most other languages do it that way. But not
    Fortran.

    Can you elaborate on what these "most other languages" are ? I
    cannot find any intrinsic function that corresponds to the "most
    natural interpretation" in most of the popular languages around (C,
    C++, Pthon, Java, Rust, Matlab...)

    Python doesn’t have a fraction() function as such, but it does have
    modf <https://docs.python.org/3/library/math.html#math.modf>, which is documented as returning “the fractional and integer parts” of its
    argument. Using the same examples as started this thread:

    ldo@theon:~> python3 -ic "import math"
    >>> math.modf(3.75)
    (0.75, 3.0)
    >>> math.modf(2.5)
    (0.5, 2.0)
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From pehache@pehache.7@gmail.com to comp.lang.fortran on Tue Sep 9 08:08:29 2025
    From Newsgroup: comp.lang.fortran

    Le 09/09/2025 à 00:16, Lawrence D’Oliveiro a écrit :
    On Mon, 8 Sep 2025 15:25:28 +0200, pehache wrote:

    Le 17/08/2025 à 09:15, Lawrence D’Oliveiro a écrit :

    The way you describe is obviously the most natural interpretation,
    these days. And most other languages do it that way. But not
    Fortran.

    Can you elaborate on what these "most other languages" are ? I
    cannot find any intrinsic function that corresponds to the "most
    natural interpretation" in most of the popular languages around (C,
    C++, Pthon, Java, Rust, Matlab...)

    Python doesn’t have a fraction() function as such,

    Neither any of the other languages. In contrast to your initial assertion.

    but it does have
    modf <https://docs.python.org/3/library/math.html#math.modf>, which is documented as returning “the fractional and integer parts” of its argument.

    Which is a behavior that you can hardly guess without reading the doc,
    same as `FRACTION()` in Fortran. And yet, you do not blame Python for that.

    Using the same examples as started this thread:

    ldo@theon:~> python3 -ic "import math"
    >>> math.modf(3.75)
    (0.75, 3.0)
    >>> math.modf(2.5)
    (0.5, 2.0)

    And Fortran has `MOD()`, that can be used to directly get the fractional
    part:

    =====================
    print*, mod(3.14,1.0)
    end
    =====================
    0.140000105
    --
    "...sois ouvert aux idées des autres pour peu qu'elles aillent dans le
    même sens que les tiennes.", ST sur fr.bio.medecine
    ST passe le mur du çon : <j3nn2hFmqj7U1@mid.individual.net>
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.fortran on Tue Sep 9 07:23:54 2025
    From Newsgroup: comp.lang.fortran

    On Tue, 9 Sep 2025 08:09:12 +0200, pehache wrote:

    Le 09/09/2025 à 00:16, Lawrence D’Oliveiro a écrit :

    Python doesn’t have a fraction() function as such,

    Neither any of the other languages. In contrast to your initial
    assertion.

    WHAT “initial assertion”?

    but it does have modf
    <https://docs.python.org/3/library/math.html#math.modf>, which is
    documented as returning “the fractional and integer parts” of its
    argument.

    Which is a behavior that you can hardly guess without reading the
    doc, same as `FRACTION()` in Fortran.

    Maybe check the actual Fortran docs and behaviour? We *did* discuss
    all this in the thread, you know.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Steven G. Kargl@sgk@REMOVEtroutmask.apl.washington.edu to comp.lang.fortran on Tue Sep 9 15:16:08 2025
    From Newsgroup: comp.lang.fortran

    On Tue, 09 Sep 2025 07:23:54 +0000, Lawrence D’Oliveiro wrote:

    On Tue, 9 Sep 2025 08:09:12 +0200, pehache wrote:

    Le 09/09/2025 à 00:16, Lawrence D’Oliveiro a écrit :

    Python doesn’t have a fraction() function as such,

    Neither any of the other languages. In contrast to your initial
    assertion.

    WHAT “initial assertion”?

    After Gary described a decimal fraction, you wrote:

    The way you describe is obviously the most natural interpretation, these
    days. And most other languages do it that way. But not Fortran.

    We're still waiting for a list of "most other languages". C does
    not have a fraction() intrinsic function.

    but it does have modf
    <https://docs.python.org/3/library/math.html#math.modf>, which is
    documented as returning “the fractional and integer parts” of its
    argument.

    Which is a behavior that you can hardly guess without reading the
    doc, same as `FRACTION()` in Fortran.

    Maybe check the actual Fortran docs and behaviour? We *did* discuss
    all this in the thread, you know.

    Seeing python's modf() does not lends itself to a "most natural interpretation", so of course you need to read the documentation.
    The same applies to C.

    PS: Fortran has MOD() and MODULO(). See the docs for the differences.
    --
    steve

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.fortran on Tue Sep 9 22:41:33 2025
    From Newsgroup: comp.lang.fortran

    On Tue, 9 Sep 2025 15:16:08 -0000 (UTC), Steven G. Kargl wrote:

    Seeing python's modf() does not lends itself to a "most natural interpretation"

    ldo@theon:~> python3 -ic "import math"
    >>> fraction = lambda x : math.modf(x)[0]
    >>> fraction(3.75)
    0.75
    >>> fraction(2.5)
    0.5
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Steven G. Kargl@sgk@REMOVEtroutmask.apl.washington.edu to comp.lang.fortran on Wed Sep 10 02:15:55 2025
    From Newsgroup: comp.lang.fortran

    On Tue, 09 Sep 2025 22:41:33 +0000, Lawrence D’Oliveiro wrote:

    On Tue, 9 Sep 2025 15:16:08 -0000 (UTC), Steven G. Kargl wrote:

    Seeing python's modf() does not lends itself to a "most natural
    interpretation"

    ldo@theon:~> python3 -ic "import math"
    >>> fraction = lambda x : math.modf(x)[0]
    >>> fraction(3.75)
    0.75
    >>> fraction(2.5)
    0.5

    ROTFL. Intent to column 7 and the following worked over 66 years ago.

    program real_kinds
    real x
    fraction(x) = mod(x,1.)
    x = 3.12345
    print *, fraction(x)
    end program real_kinds

    % gfcx -o z a.f90 && ./z
    0.123450041


    So, how is a user without looking at the documentation
    to know what modf()?
    --
    steve
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From pehache@pehache.7@gmail.com to comp.lang.fortran on Wed Sep 10 08:21:51 2025
    From Newsgroup: comp.lang.fortran

    Le 09/09/2025 à 09:23, Lawrence D’Oliveiro a écrit :
    On Tue, 9 Sep 2025 08:09:12 +0200, pehache wrote:

    Le 09/09/2025 à 00:16, Lawrence D’Oliveiro a écrit :

    Python doesn’t have a fraction() function as such,

    Neither any of the other languages. In contrast to your initial
    assertion.

    WHAT “initial assertion”?

    Memory issues?

    You wrote: "The way you describe is obviously the most natural
    interpretation, these days. And most other languages do it that way. But
    not Fortran."

    We are still waiting what are these natural ways to get a fractional
    part of these other languages.


    but it does have modf
    <https://docs.python.org/3/library/math.html#math.modf>, which is
    documented as returning “the fractional and integer parts” of its
    argument.

    Which is a behavior that you can hardly guess without reading the
    doc, same as `FRACTION()` in Fortran.

    Maybe check the actual Fortran docs and behaviour?

    This is precisely the advice you have received, instead of complaining
    that `FRACTION()` doesn't do what you thought it was doing. Memory issue again?

    We *did* discuss
    all this in the thread, you know.

    I'm not the one here that forgets what he has written in the previous messages.
    --
    "...sois ouvert aux idées des autres pour peu qu'elles aillent dans le
    même sens que les tiennes.", ST sur fr.bio.medecine
    ST passe le mur du çon : <j3nn2hFmqj7U1@mid.individual.net>
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From pehache@pehache.7@gmail.com to comp.lang.fortran on Wed Sep 10 08:25:04 2025
    From Newsgroup: comp.lang.fortran

    Le 10/09/2025 à 00:41, Lawrence D’Oliveiro a écrit :
    On Tue, 9 Sep 2025 15:16:08 -0000 (UTC), Steven G. Kargl wrote:

    Seeing python's modf() does not lends itself to a "most natural
    interpretation"

    ldo@theon:~> python3 -ic "import math"
    >>> fraction = lambda x : math.modf(x)[0]
    >>> fraction(3.75)
    0.75
    >>> fraction(2.5)
    0.5

    And how do you know how `modf()` works without reading the documentation?
    --
    "...sois ouvert aux idées des autres pour peu qu'elles aillent dans le
    même sens que les tiennes.", ST sur fr.bio.medecine
    ST passe le mur du çon : <j3nn2hFmqj7U1@mid.individual.net>
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.fortran on Wed Sep 10 07:02:03 2025
    From Newsgroup: comp.lang.fortran

    On Wed, 10 Sep 2025 08:21:51 +0200, pehache wrote:

    We are still waiting what are these natural ways to get a fractional
    part of these other languages.

    Let me try again:

    ldo@theon:~> python3 -ic "import math"
    >>> fraction = lambda x : math.modf(x)[0]
    >>> fraction(3.75)
    0.75
    >>> fraction(2.5)
    0.5

    This is precisely the advice you have received, instead of complaining
    that `FRACTION()` doesn't do what you thought it was doing.

    Here’s what I said, again:

    “The way you describe is obviously the most natural interpretation, these days. And most other languages do it that way. But not Fortran.”
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.fortran on Wed Sep 10 07:03:42 2025
    From Newsgroup: comp.lang.fortran

    On Wed, 10 Sep 2025 08:25:04 +0200, pehache wrote:

    Le 10/09/2025 à 00:41, Lawrence D’Oliveiro a écrit :

    ldo@theon:~> python3 -ic "import math"
    >>> fraction = lambda x : math.modf(x)[0]
    >>> fraction(3.75)
    0.75
    >>> fraction(2.5)
    0.5

    And how do you know how `modf()` works without reading the
    documentation?

    The point being, it gives a more natural (i.e. less-surprising) result
    than Fortran. That is the point I was trying to make -- the nub of my
    gist, if you will. Or even if you won’t. Do not try to distract from that. --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.fortran on Wed Sep 10 07:06:53 2025
    From Newsgroup: comp.lang.fortran

    On Wed, 10 Sep 2025 02:15:55 -0000 (UTC), Steven G. Kargl wrote:

    Intent to column 7 and the following worked over 66 years ago.

    program real_kinds
    real x
    fraction(x) = mod(x,1.)
    x = 3.12345
    print *, fraction(x)
    end program real_kinds

    Ignoring the fact that’s not valid FORTRAN 66 or FORTRAN IV (what other
    spec was valid 66 years ago?), it’s not relevant to the FRACTION()
    function we are discussing, is it?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Steven G. Kargl@sgk@REMOVEtroutmask.apl.washington.edu to comp.lang.fortran on Wed Sep 10 22:03:04 2025
    From Newsgroup: comp.lang.fortran

    On Wed, 10 Sep 2025 07:03:42 +0000, Lawrence D’Oliveiro wrote:

    On Wed, 10 Sep 2025 08:25:04 +0200, pehache wrote:

    Le 10/09/2025 à 00:41, Lawrence D’Oliveiro a écrit :

    ldo@theon:~> python3 -ic "import math"
    >>> fraction = lambda x : math.modf(x)[0]
    >>> fraction(3.75)
    0.75
    >>> fraction(2.5)
    0.5

    And how do you know how `modf()` works without reading the
    documentation?

    The point being, it gives a more natural (i.e. less-surprising) result
    than Fortran. That is the point I was trying to make -- the nub of my
    gist, if you will. Or even if you won’t. Do not try to distract from
    that.

    And we've pointed out that the "most other languages" that you
    referenced do not have a fraction() function. Your python
    example defines a fraction() function in terms of modf().
    You had to read the documentation to know what modf() does.
    Well, if you're going to read python documentation, then if
    you get an unexpected result with Fortran's fraction() you
    may want to actually read Fortran documentation.
    --
    steve
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Steven G. Kargl@sgk@REMOVEtroutmask.apl.washington.edu to comp.lang.fortran on Wed Sep 10 22:28:22 2025
    From Newsgroup: comp.lang.fortran

    On Wed, 10 Sep 2025 07:06:53 +0000, Lawrence D’Oliveiro wrote:

    On Wed, 10 Sep 2025 02:15:55 -0000 (UTC), Steven G. Kargl wrote:

    Intent to column 7 and the following worked over 66 years ago.

    program real_kinds
    real x fraction(x) = mod(x,1.)
    x = 3.12345 print *, fraction(x)
    end program real_kinds

    Ignoring the fact that’s not valid FORTRAN 66 or FORTRAN IV (what other spec was valid 66 years ago?), it’s not relevant to the FRACTION()
    function we are discussing, is it?

    Yeah, A little loose with syntax. You however are overlooking
    the key point: F66 had a statement function.

    FRAC(X) = AMOD(X, 1.)
    X = 3.12345
    Y = FRAC(X)
    WRITE(7) Y
    END

    This is your python example of a user written fraction()
    function, and is Fortran 66 conforming. So, returning to modern
    Fortran, if you want fraction() to return the decimal fractional
    part of a number, use a statement function or better yet a
    contained subprogram.


    program foo
    implicit none
    real x
    x = 3.12345
    print *, fraction(x)
    contains
    elemental function fraction(x) result(r)
    real r
    real, intent(in) :: x
    r = mod(x,1.)
    end function fraction
    end program foo
    --
    steve
    --- Synchronet 3.21a-Linux NewsLink 1.2